0

我在舞台上有按钮(run1_btn - run5-btn),单击这些按钮会将影片剪辑添加到舞台。(手)影片剪辑包含几帧动画。单击按钮时,会添加影片剪辑,但动画已经完成。我以为当 mc 添加到舞台上时,动画就会开始,但事实似乎并非如此。有谁知道解决这个问题的方法。

这是我的代码:

var handSlap:hand;
handSlap = new hand();

//event listeners
newPig.run1_btn.addEventListener(MouseEvent.CLICK, clickArea);
newPig.run2_btn.addEventListener(MouseEvent.CLICK, clickArea);
newPig.run3_btn.addEventListener(MouseEvent.CLICK, clickArea);
newPig.run4_btn.addEventListener(MouseEvent.CLICK, clickArea);
newPig.run5_btn.addEventListener(MouseEvent.CLICK, clickArea);




//functions
function clickArea(evtObj:MouseEvent):void
{
    trace(evtObj.target.name);
    addChild(handSlap);
    handSlap.x =200;
    handSlap.y=200;

}
4

2 回答 2

1

可能更优雅(取决于您的观点),它确保在任何情况下手在添加到舞台时都会重新启动其时间线动画:

hand.addEventListener(Event.ADDED_TO_STAGE, onHandAddedToStage, false, 0, true);
function onHandAddedToStage(event:Event):void
{
    var mc:Movieclip = MovieClip(event.currentTarget);
    mc.gotoAndPlay(1);
}

如果您不熟悉事件模型,“false, 0, true” 位只是确保如果您需要卸载手,它不会被事件侦听器卡住并留在内存中,可能您不需要不需要它,但它没有害处。

于 2009-12-04T06:04:22.997 回答
0
  var newPig:pig;
newPig = new pig();
addChild(newPig);
newPig.y=360;
newPig.x=350;

var handSlap:hand;
handSlap = new hand();

//event listeners
newPig.run1_btn.addEventListener(MouseEvent.CLICK, clickArea);
newPig.run2_btn.addEventListener(MouseEvent.CLICK, clickArea);
newPig.run3_btn.addEventListener(MouseEvent.CLICK, clickArea);
newPig.run4_btn.addEventListener(MouseEvent.CLICK, clickArea);
newPig.run5_btn.addEventListener(MouseEvent.CLICK, clickArea);

handSlap.addEventListener(Event.ADDED_TO_STAGE, onHandAddedToStage, false, 0, true);


//functions
function clickArea(evtObj:MouseEvent):void
{
    trace(evtObj.target.name);

    addChild(handSlap);
    handSlap.x =200;
    handSlap.y=200;


}

function onHandAddedToStage(event:Event):void
{
    var mc:MovieClip = MovieClip(event.currentTarget);
    mc.gotoAndPlay(1);
}
于 2009-12-10T09:53:19.077 回答