as3 | trying to add multiple "onClick" events - how do I do that?
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/
精彩评论