简体   繁体   中英

create own frames animation and play in movieclip


how can i create own frames animation and play in movieclip or any movieclip extends.. i have this code but is wrong - i'm flash builder beginner so i don't know how work it..i can do it in MovieClip

<?xml version="1.0" encoding="utf-8"?>

        public var mc:MovieClip;
        protected function application1_creationCompleteHandler(event:FlexEvent):void
        {
            var comp:UIComponent = new UIComponent();
            this.addElement(comp);

            mc = new MovieClip();

            for (var i:int =0; i<100; i++)
            {   
                var rect:Sprite = new Sprite();
                rect.graphics.beginFill(0x330000);
                rect.graphics.drawCircle(0, 0, 20);
                rect.graphics.endFill();
                rect.x=30 + (i%40)*5;
                rect.y=100;
                mc.addChild(rect);
            }
            comp.addChild(mc);
        }


        protected function button1_clickHandler(event:MouseEvent):void
        {
            mc.play();
        }
    ]]>
</fx:Script>

<s:Button click="button1_clickHandler(event)"/>

thanks for help

Sadly there is no way to create MovieClip animations at runtime, they can only be created using Flash Authoring (or possibly other tools that can export to swf).

Your options are to either create a bunch of Sprite or possibly Shape and add/remove these from the display list as you progress throught the frames. Another option, if your graphics are simpler, you can generate them on the fly for each frame.

I think we'd need a bit more information about the type of animation you're hoping to create.

Depending on what it is, it could be very possible in theory. You'd be creating a separate class that extends MovieClip and instantiate that in your 'for loop'. That class could have all sorts of animation instructions and logic. Extending 'MovieClip' isn't the only option, but it does enable you to use Event.ENTER_FRAME where with a Sprite you'd need to set up an internal Timer or use a public 'update' or 'draw' method that can be called from your main code.

There are also 'Motion' classes that allow you to load XML animation instructions that you have a fair amount of control with. Look up fl.motion.Animator.

What are you trying to do? Welcome to ActionScript!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM