Roger Jarvis
Roger Jarvis

Reputation: 434

Embedded .swf animation not stopping on stop() call?

I have a .swf animation that I created in Flash Professional. To use it in my actionscript project, I embed it as follows:

[Embed(source="../lib/fetching.swf")]
public var Fetching:Class;

I then create an instance and add it to the stage as follows:

//class variable
var mc:MovieClip;

mc = new Fetching();
this.addChild(mc);

This causes my animation to appear on the screen and loop indefinitely. However, when calling mc.stop(), the animation does not stop. I've tried removing the movieclip from the stage by calling removeChild(mc) but adding a listener on the ENTER_FRAME event told me the movieclip is still playing over and over.

Upvotes: 3

Views: 1530

Answers (2)

Jude Fisher
Jude Fisher

Reputation: 11294

Have you checked to be sure the embedded clip is compiled for the AVM2 (ie. that it targets AS3 and not AS1 or AS2)? An Avm1 swf may cast to a MovieClip without throwing an error, but will not then respond to commands.

Upvotes: 1

bitmapdata.com
bitmapdata.com

Reputation: 9600

you should set a Embed source mimeType, and you convert to ByteArray. and loaded. because you can't Direct Type Casting Fetching Class to MovieClip. If you define explicitly mimeType and convert by force, you'll get about TypeError #1034: Type Coercion failed: cannot convert YourProject_Fetching@108b780d1 to flash.display.MovieClip

refer a following code.

package
{
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.utils.ByteArray;

    public class TestProject extends Sprite
    {
        [Embed(source="../lib/fetching.swf", mimeType="application/octet-stream")]
        public var Fetching:Class;

        public var loader:Loader = new Loader();

        private var mc:MovieClip;

        public function TestProject()
        {
            loader.loadBytes( new Fetching() as ByteArray );
            loader.contentLoaderInfo.addEventListener(Event.INIT, onSwfLoaded);
            this.addChild(loader);
        }

        private function onSwfLoaded(e:Event):void 
        {
            mc = loader.content as MovieClip;
            mc.stop();
        }
    }
}

Upvotes: 3

Related Questions