【问题标题】:Stop animation of a movie clip in flash Action Script 3在 Flash 动作脚本 3 中停止影片剪辑的动画
【发布时间】:2013-06-15 10:16:24
【问题描述】:

我是 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);
}

【问题讨论】:

  • removeChild(firegun); 在计时器之后

标签: actionscript-3 flash game-engine movieclip flash-cs6


【解决方案1】:

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

可能是这样的:

// 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);
    }
}

【讨论】:

  • TypeError:错误 #1006:removeSelfWhenDone 不是函数。在 Game_fla::MainTimeline/removeSelfWhenDone() 这就是我这样做时得到的......
  • 请尝试下载 fla,以便您可以看到我的屏幕上的内容。
  • 我用cs5打不开。但其目的是为影片剪辑本身添加一个事件帧侦听器,用于监控影片何时播放完毕。
  • 好吧..我试图修改代码并尝试但它没有工作,sry.
猜你喜欢
  • 1970-01-01
  • 2015-04-24
  • 1970-01-01
  • 2011-07-13
  • 1970-01-01
  • 2013-04-04
  • 1970-01-01
  • 2013-01-27
  • 1970-01-01
相关资源
最近更新 更多