开发者

Control loaded swish animation in AS 3.0

开发者 https://www.devze.com 2023-03-09 20:41 出处:网络
I\'m developing an AS 3.0 wrapper to add some extra stuff that has to load some old and plain frame to frame SwishMax 3 animations and then be able to stop them, play them, and so...

I'm developing an AS 3.0 wrapper to add some extra stuff that has to load some old and plain frame to frame SwishMax 3 animations and then be able to stop them, play them, and so...

Here is my code:

package {

    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageS开发者_C百科caleMode;
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.net.URLRequest;
    import flash.events.*;

    [SWF(backgroundColor="#ffffff", frameRate="17", width="300", height="250")]

    public class SwishMaxWrapper extends Sprite {

        function SwishMaxWrapper() {

            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;

            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
            addChild(loader);

            var request:URLRequest = new URLRequest("swishy.swf");
            loader.load(request);

        }

        private function completeHandler(event:Event):void {

            var movie:MovieClip = event.target.content;
            movie.stop();

        }

    }

}

The animation load works as expected but the movie.stop() doesn't. What is wrong?


I tested your code and it works on my machine. The SWF that I loaded had its animation in the main timeline. Is it possible that the swishy.swf has animation that is not on the main timeline? Perhaps the animation is in another symbol instead, and an instance of that symbol is on the stage. Anyway, when you call stop() in your code above, it's just telling the main timeline to stop, but other movie clips on the stage will keep on going.

I think that's what Simsoft was pointing out.

I tested your code using a SWF that had a symbol on the stage that had animation in it, and I got the problem that you are describing. I fixed it by modifying completeHandler() as follows:

public function completeHandler(event:Event):void {

    var movie:MovieClip = event.target.content;
    movie.stop();  //doesn't work - main timeline is only one frame long

    for(var i:int = 0; i<movie.numChildren; i++) {
        var child:MovieClip = movie.getChildAt(i) as MovieClip;
        if(child) {  //need this test - if the cast to MovieClip fails, child will be null
            child.stop(); //works
        }
    }
}

Hopefully you don't have more animations nested at deeper layers. If that's the case, you'll have to modify this to keep peering into the children of each child and trying to stop their timelines as well.

Anyway, hope that helps. Good luck!


stop() isn't recurive, I think the problem is here.

 function ruleThemAll(target : DisplayObjectContainer, doStop : Boolean = true) : void
   {
      for(var i : uint = 0; i < target.childNum; ++i)
      {
         var child : DisplayObject = target.getChildAt(i);

         // If it's a container, go into to stop children
         if(child is DisplayObjectContainer)
            ruleThemAll(child as DisplayObjectContainer, doStop);

         if(child is MovieClip)
         {
             if(doStop)
                MovieClip(child).stop();
             else
                MovieClip(child).play();
         }
      }
   }
0

精彩评论

暂无评论...
验证码 换一张
取 消