as3 |试图添加多个“onClick”事件 - 我该怎么做?

时间:2011-06-10 16:39:48

标签: flash actionscript-3 onclick flash-cs5 addeventlistener

我正在尝试创建多个addEventListener,但我不知道如何。正如你在下面的代码中看到的那样 - 我不明白我写的地方需要写什么????????为了产生多个功能(例如onClick1,onClick2,onClick3等......)

for (i=0; i < numberOfResults; i++)
{
    videoResults[i] = new Object();
    videoResults[i].movie = new MovieClip();
    stage.addChild(videoResults[i].movie);
    videoResults[i].movie.addEventListener("click",?????????);
    function ?????????(event)
    {

    }

}

我需要做什么?

1 个答案:

答案 0 :(得分:2)

您不想在for循环中编写函数。做这样的事情:

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
}

您可能对Flash上​​的免费视频教程网站感兴趣:

http://gotoandlearn.com/