开发者

as3 | trying to add multiple "onClick" events - how do I do that?

开发者 https://www.devze.com 2023-03-12 14:46 出处:网络
I am trying to create multiple addEventListener but I don\'t know how. As you can see in the code below - I don\'t understand what I need to write where I wrote ???????? in order to produce multiple f

I am trying to create multiple addEventListener but I don't know how. As you can see in the code below - I don't understand what I need to write where I wrote ???????? in order to produce multiple functions (such as onClick1,onClick2,onClick3, etc...)

for (i=0; i < numberOfResults; i++)
{
    videoResults[i] = new Object();
    videoResults[开发者_如何学Ci].movie = new MovieClip();
    stage.addChild(videoResults[i].movie);
    videoResults[i].movie.addEventListener("click",?????????);
    function ?????????(event)
    {

    }

}

What do I need to do?


You don't want to write a function inside of a for loop. Do something like this:

for (i=0; i < numberOfResults; i++)
{
    videoResults[i] = new Object();
    videoResults[i].movie = new MovieClip();
    stage.addChild(videoResults[i].movie);
    videoResults[i].movie.addEventListener(MouseEvent.MOUSE_DOWN, myMadeUpCallbackEvent);    
}


function myMadeUpCallbackEvent(evt:MouseEvent):void
{
   //In order to be able to tell which clip has called this callback, you can compare the properties of evt.currentTarget. The evt is the Event object cast into a reference. evt.currentTarget is the target or object that called the event. So you can do something like this:
   trace(MovieClip(evt.currentTarget).name); to get the unique name of the caller
}

You may be interested in this free video tutorial website on flash:

http://gotoandlearn.com/

0

精彩评论

暂无评论...
验证码 换一张
取 消