0

我是 Flash 的新手..(不是很新),我想问一个问题。我刚刚制作(正在进行中)一个游戏,我们必须射击从天上掉下来的人。我打算制造敌人,但我想制造一些效果……比如射击。我做了一个效果,在我点击的地方,一个新的孩子被制作出来,它是一个爆炸的电影剪辑动画。但我无法停止动画。它继续循环。我试过了 stop(); 在符号的最后一帧中,但它甚至不会在屏幕上添加孩子。这是 .fla 文件:-

http://www.mediafire.com/download/lwol38o4454sphp/Game.fla

这是代码:-

import flash.events.Event;
import fl.motion.MotionEvent;

addEventListener (Event.ENTER_FRAME,moveturret);
Mouse.hide();
var firegun:boom22 = new boom22();

function moveturret (e:Event)

{
    aim.x = mouseX
    aim.y = mouseY
    var differenceX = mouseX - turret.x;
    var differenceY = mouseY - turret.y;
    var radianToDegrees = (Math.PI/180);
    turret.rotation = Math.atan2(differenceY, differenceX)/radianToDegrees;
}


stage.addEventListener(MouseEvent.CLICK,fire);

function fire (e:MouseEvent)

{
    firegun.x = mouseX
    firegun.y = mouseY
    addChild(firegun);
}
4

1 回答 1

0

您可以添加一个事件侦听器来检查剪辑何时播放完毕,然后让它自行移除。

也许是这样的:

// within your fire() event handler
addChild(firegun);
firegun.gotoAndPlay(1); // just in case
firegun.addEventListener(Event.ENTER_FRAME, removeSelfWhenDone, false, 0, true);



// then new method:
// on every frame tick, check if last frame is reached, if so, remove it from it's parent (which would be the stage)
function removeSelfWhenDone(inputEvent:Event):void {
    var clip:MovieClip = (MovieClip) (inputEvent.target);
    if(clip.currentFrame == clip.totalFrames){
        // also remove the event listener (as it gets added again later)
        clip.removeEventListener(Event.ENTER_FRAME, removeSelfWhenDone, false);
        clip.parent.removeChild(clip);
    }
}
于 2013-06-15T10:35:31.360 回答