gotoAndPlay不适用于外部加载的SWF

时间:2014-04-11 05:26:07

标签: actionscript-3

我有一个外部swf是一个角色动画。我成功加载它并将其存储在MovieClip变量中并将其添加到舞台上。它开始在第0帧播放,一切正常,但我不能让gotoAndPlay或gotoAndStop工作。我可以找出MovieClip的currentFrame,所以我可以访问时间轴。使用gotoAndPlay时没有任何flash错误,或者gotoAndStop只是简单的没有对MovieClip做任何事情。

我不知道为什么一切都会有效。任何提示都非常感激。

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoaderComplete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, LoaderError);
loader.load(new URLRequest("file.swf");

private function LoaderComplete(e:Event):void 
{
    var character:MovieClip = e.target.content as MovieClip;
    stage.addChild(character);
    character.gotoAndStop(10);
}

2 个答案:

答案 0 :(得分:1)

我认为加载的swf文件的主时间轴不是你的角色,这就是你永远得到currentFrame 1的原因。

//This line of code, gives you reference on main timeline
var mainTimeline:MovieClip = e.target.content as MovieClip; 
//Check if there is character
//If I'm correct, numChildren will return 1 or more
trace(mainTimeline.numChildren);
//If yes, access character animation
//Like this:
var char: MovieClip = mainTimeline.getChildAt(0) as MovieClip;
char.gotoAndStop(10);

答案 1 :(得分:1)

可能是你将它添加到舞台的那一刻,不知道它有多个帧。尝试侦听added_to_stage事件,然后转到框架,如:

private function LoaderComplete(e:Event):void 
{
  var character:MovieClip = e.target.content as MovieClip;
  stage.addChild(character);
  character.addEventListener(Event.ADDED_TO_STAGE, gotoTheFrame);
}

private function gotoTheFrame(e:Event){
  var target:MovieClip = MovieClip(e.target);
  target.gotoAndStop(10);
}