0
votes

I have an external swf that is a character animation. I successfully load it and store it in a MovieClip variable and add it to the stage. It starts playing at frame 0 and everything works fine except that I can't get gotoAndPlay or gotoAndStop to work. I can trace out the currentFrame of the MovieClip, so I have access to the timeline. I don't get any flash errors when using gotoAndPlay, or gotoAndStop it just simple isn't doing anything to the MovieClip.

I am at a loss as to why everything but this would work. Any tips greatly appreciated.

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
Show some code on what you have tried so far?Rajneesh Gaikwad
For a little more information, it seems to think the character.currentFrame is always 1, even as its looping through the animation.Josh Brittain

2 Answers

1
votes

I think main timeline of the loaded swf file isn't your character, that is why you are getting always 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
votes

It could be that the moment you adding it to the stage, it is unknown it has multiple frames. Try listening for the added_to_stage event and THEN goto the frame, like:

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