2

I would be very thankful if you help me with this problem. I´m trying to play in my application for ipad one MovieClip once. i tried to do stopping in this way, but the movie dont stop

var loader:Loader = new Loader();
var swfFile:URLRequest= new URLRequest("/test.swf");
loader.load(swfFile);

movieClip = new MovieClip();
movieClip.addChild(loader);
movieClip.addFrameScript(movieClip.totalFrames - 1, callbackFunc);
movieClip.play();
private function callbackFunc():void
{
movieClip.stop();
}
strah
  • 6,702
  • 4
  • 33
  • 45
Sadako
  • 352
  • 3
  • 18
  • Hmm. What did you expect from a `new MovieClip()`? It has 1 empty frame, and can not play anything. Callbacks added by `addFrameScript()` are triggered as if their code was just written inside the designated frame. – Michael Antipin May 18 '12 at 13:23
  • In short: your `movieClip` doesn't have frames to add script to. Try `trace(movieClip.currentFrame);` which will output `0`, notice that `movieClip.currentFrame` for MovieClips created at design time is always greater than 0. – Michael Antipin May 18 '12 at 13:30

3 Answers3

2
var loader:Loader = new Loader();
var swfFile:URLRequest= new URLRequest("/test.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onFileLoaded);
loader.load(swfFile);

//I assume you have declared 'movieClip'?
//if not do:
//var movieClip:MovieClip;


private function onFileLoaded(e:Event):void
{
    movieClip = loader.content;
    addChild(movieClip);
    movieClip.play();
    addEventListener(Event.ENTER_FRAME, onEnter, true, 0, false);
}

private function onEnter(e:Event):void
{
    if (movieClip.currentFrame == movieClip.totalFrames)
    {
        movieClip.stop();
        removeEventListener(Event.ENTER_FRAME, onEnter, true, 0, false);
        //do other stuff
    }
}

This should do what you need.

strah
  • 6,702
  • 4
  • 33
  • 45
2
var loader:Loader = new Loader(); 
var swfFile:URLRequest= new URLRequest("/test.swf"); 
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
loader.load(swfFile); 

private function callbackFunc():void 
{ 
    movieClip.stop(); 
} 

function onCompleteHandler(loadEvent:Event)
{
    movieClip = MovieClip(loadEvent.currentTarget.content);
    addChild(movieClip);

    movieClip.addFrameScript(movieClip.totalFrames - 1, callbackFunc); 
    movieClip.play(); 
}
aKzenT
  • 7,775
  • 2
  • 36
  • 65
2

Your code will not work because it's not the movieClip that is played, it's the external SWF that you load into it that will play it's keyframes. The created movieClip only has 1 keyframe, and on that 1 keyframe the external SWf is placed. You should add the stop() function into the external SWF. If you do this correct the external SWF plays once, and is then stopped.

You can also wrap the external SWF into a new MovieClip and put the code you already have onto it...

Or If you want full control, you can adapt the external SWF code so that this dispatches an event when the last frame is played. Provide a custom stop / replay function on the SWF which you can then call from the parent SWF.

Good luck!

CGBe
  • 183
  • 1
  • 11