MovieClip vs Sprite

the following post i found on another blog I Think it's very use full for those who are new in as3.

Display Objects
One of the changes in ActionScript 3 is to be working with display objects.

  • MovieClip (flash.display.MovieClip)
  • Sprite (flash.display.Sprite) – like a MovieClip but with no frames. They are a new kind of light-weight MovieClip that doesn’t technically have any frames. Since MovieClip instances you create dynamically through ActionScript cannot have frames anyway, chances are you’d want to use a Sprite in place of a MovieClip for all dynamically created MovieClip instances.
  • Shape (flash.display.Shape) – like a Sprite but with no mouse or keyboard interactivity. They are like Sprites but they offer mouse or keyboard interactivity. In other words, these display objects cannot receive events like mouseDown or keyUp. Shape instances cannot contain any other kind of display objects nor have children of their own. You can only draw vector shapes within them using the vector drawing API‘s (beginFill, lineTo, endFill, etc). This comes as an advantage to Shapes since they use less memory and are more efficient than MovieClips and Sprites.
  • Bitmap (flash.display.Bitmap) – like a Sprite but used only for displaying bitmap images. They are much like Shapes except instead of being able to contain vector drawings; they contain bitmap images defined by a BitmapData instance. They, too, cannot contain any other display objects or children. They can interact with the mouse and keyboard.
  • Loader (flash.display.Loader) – like a Sprite but used specifically to display and contain loaded content (SWFs and images).Like Sprite, has no timeline, but is designed specifically to facilitate the loading of external display content such as external SWFs and bitmap images. When loaded, those assets displayed in the Loader instance and are accessible through the Loader’s content property.

Why, when and how should people extend the Sprite in a class vs. the MovieClip class?
It seems like they’re the same thing… but I know that a sprite is at a lower level… what benefits do you get from using sprites instead of movieclips? Or movieclips instead of sprites?

Movie clips are sprites with a timeline and methods/properties to manipulate it. Use Sprite unless you require a timeline. And if you don’t require the functionality of DisplayObjectContainer (child movie clips) and InteractiveObject (mouse events, enterFrame, etc) then you should use Shape, which is light weight and simple but Shapes do have enterFrame events ;) just not the interactive stuff - mouse or keyboard interaction :) The MovieClip class is dynamic, to make the transition to AS3 easier, whereas the Sprite class are static. You can use Sprite as a class for movieclip symbols in your timeline but you cannot navigate to any frame beyond frame 1 and you cannot have ActionScript placed on that timeline. For any of that, you would want to stick to MovieClip. And if not using any timeline features there’s no point in using MovieClip… unless you want an automatically dynamic sprite without making your own subclass ;)
Sprite is a little less memory because they don’t have to worry about frames. If u want to draw stuffs and don’t need mouse or keyboard events then its wise use shape…


Anonymous said...

For bitmap you said
"They can interact with the mouse and keyboard."

But how can they interact if they do not inherit InteractiveObject class?

Or am I missing something?

PHP developer Cochin |PHP developer Kerala | PHP developer India | Flash developer/programmer Cochin | Flash developer/programmer Kerala | Flash developer/programmer India | web programmer kerala |web programmer Cochin |web programmer India |web developer kerala |Web developer Cochin | Kerala PHP | PHP freelancer| flash actionscript freelancer