开发者

How do I make a movieclip appear using as3?

I have a movieclip in my library. I want to be able to make it appear on stage and be 开发者_如何学JAVAmoved to where I want it to be. I will need up to 18 instances of this single movieclip. How do I do this (using AS3)?


You seem to be asking a lot of questions lately.

First off, right click on the MovieClip in the Library, and click Properties. Be sure to enable "Export for Actionscript". Under linkage, give it a class name (remember, first letter should be capitalized). For example, I'll use MovieClipClass.

In your document class (I used Main.as, which is in the same folder as test.fla):

package  
{
    import flash.display.Sprite;
    import MovieClipClass;
    public class Main extends Sprite
    {
        private var _container:Sprite;
        public function Main() 
        {
            addContainer();
        }

        private function addContainer():void
        {
            _container = new Sprite();
            addChild(_container);
            //add "18" movieclips to _container
            addMovieClips(18, _container);
        }

        private function addMovieClips(limit:int, container:Sprite):void
        {
            for(var i:int=0;i<limit;i++)
            {
                var mc:MovieClipClass = new MovieClipClass();
                container.addChild(mc);
                //random x and y generated by stage width and height
                mc.x = Math.floor(Math.random() * stage.stageWidth);
                mc.y = Math.floor(Math.random() * stage.stageHeight);
            }
            container.x = 0;
            container.y = 0;
        }

    }

}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜