开发者

Basic MovieClip usage in FlashDevelop

I'm just started doing 'hands-on' learning of Actionscript 3 using FlashDevelop.

I've now managed to subclass a sprite, load a graphic from the library, and manipulate it around the stage. Next step is doing the same with a MovieClip, but it doesn't seem to be as simple.

Basically, I want a simple subclass of MovieClip, that uses a SWF that I created & exported in Flash CS5 (anything else that can create them?), and then added it into my library in FlashDevelop.

In my 'Main' class, I want something like this:

package 
{
    import flash.display.MovieClip;
    import flash.events.Event;

    public class Main extends Sprite 
    {
        private var myClip:MovieClip;

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            myClip = new MyMovieClip();
            addChild(myMovieClip);          
        }
    }
}

So, for my subclass, I was looking at something, like this:

package  
{
    import flash.display.MovieClip;

    [Embed(source = '../lib/MyButton.swf', mimeType = 'application/octet-stream')]
    public class MyMovieClip extends MovieClip
    {
        public function MyMovieClip() 
        {
      // Empty
        }
    }
}

But that didn't work. Then I tried:

package  
{
    import flash.display.MovieClip;

    public class MyMovieClip extends MovieClip
    {
        [Embed(source = '../lib/MyButton.swf', mimeType = 'application/octet-stream')]
        private var MyMovieLivClass:Class;
        private var myClip:MovieClip;

        public function MyMovieClip() 
        {
            myClip = new MyMovieLivClass() as MovieClip;    
            addChild(myClip);           
        }
    }
}

But that says the child is null, and I'm not sure I should be creating a 'new' MovieClip in开发者_StackOverflow中文版side my sub-classed MovieClip anyways.

What is the step I'm missing here?


In your last sample, you used Embed correctly (you can't slap it on class declaration). If myClip is null, this means cast as MovieClip failed and MyButton.swf gives some other type. If MyButton.swf has only one frame, it will be Sprite and not MovieClip.

EDIT: I wish I'd notice this earlier. Your clip is embedded as ByteArrayAsset with mimeType of raw bytes. Remove mimeType from Embed and compiler will make it MovieClipAsset, which is MovieClip.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜