MovieClip vs Sprite in Actionscript 3.0

10,074

Quoting from an AS3 book:

Prior to ActionScript 3.0, the MovieClip class was used as an all-purpose graphics container (much like ActionScript 3.0s Sprite class is used). As of ActionScript 3.0, MovieClip is used only to control instances of movieclip symbols created in the Flash authoring tool. Because ActionScript 3.0 does not provide a way to create timeline elements such as frames and tweens, there is no need to create new empty movieclips at runtime in ActionScript 3.0. Instead, all programmatically created graphics should be instances of the appropriate core display class (Bitmap, Shape, Sprite, TextField, etc).

MovieClip is a dynamic class that retains backwards compatibility with AS2. That means that if, while not recommended, require you add a property to a MovieClip, you can simply say myMC.myCustomProperty = "someValue", whereas with a Sprite, that will throw an error.

For this reason, they also say that using Sprites is more effective in terms of performance. You can find a discussion about this in this Adobe Forum post.

Share:
10,074
Umesh Patil
Author by

Umesh Patil

Software Analyst

Updated on June 04, 2022

Comments

  • Umesh Patil
    Umesh Patil almost 2 years

    What more can be done if I extend MainClass with MovieClip rather than Sprite. I know that MovieClip extends Sprite and it has Timeline defined under it. but still how it will be usable to me by MovieClip ?

    package  {
        import flash.display.Sprite;
        import flash.text.TextField;
        import flash.text.TextFormat;
        import flash.display.MovieClip;
        import flash.text.TextFieldType;
    
        public class MainClass extends Sprite{      
            public function MainClass() {   
    
                var m:Module=new Module("Admin","John");
    
                var tf:TextField=new TextField();
                tf.text=m.info;
                tf.border=true;
                tf.type=TextFieldType.INPUT;
    
                var myFormat:TextFormat = new TextFormat();
                myFormat.size = 3;
                tf.defaultTextFormat=myFormat;
    
                addChild(tf);   
                this.width=500;
                this.height=300;
                this.x=0;
                this.y=10;
            }
        }       
    }
    
    
    class Module{
            private var m_mName:String;
            private var m_owner:String;
    
            public function Module(mName:String,owner:String):void{
                m_mName=mName;
                m_owner=owner;
            }
            public function get info():String{
                return owner+' is owner of '+mName;
            }
            public function get mName():String{
                return m_mName;
            }
            public function get owner():String{
                return m_owner;
            }       
        }
    

    Another little question, How to use Timeline if I replace Sprite by MovieClip ?