as3 play movieclip once

折月煮酒 提交于 2019-12-11 03:27:26

问题


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

回答1:


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.




回答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(); 
}



回答3:


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!



来源:https://stackoverflow.com/questions/10652979/as3-play-movieclip-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!