Flash / AS

Silverlight

WPF

ASP.net / PHP

Photoshop

Forums

Blog

About

 


FlashComponents
  Galleries
  Slideshows
  Menus
  Design & Effects
  Audio & Video
  User Interface
  Templates

 

 

 

 


AS1 OOP: Custom Classes with MovieClips
         by senocular  

Introduction
Classes can be created not only to hold and handle data and information as scripted objects residing in memory, but also to pose as controllers for movieclip objects on the screen. What this means is that you can create a custom class in Actionscript that can be used as the primary class of a movieclip.

By default, all movieclips on the screen are instances of the type MovieClip. They are based on the MovieClip class in Actionscript and inherit methods and properties from the MovieClip prototype (properties like hitTest and getDepth etc.). To have your own classes work with movieclip instances on the screen, you would want to have them extend the MovieClip class.

There is only one little problem. Movieclip instances aren't created like other object instances using new keyword in combination with a class constructor. They are created internally by Flash as they not only exist as containers for information memory, but also as visual elements on the screen. That requires more goings on than what's required with normal object creation. Flash needs to get down and dirty with the library and copying visual symbols on to the timeline and so on. Because of that, your movieclip extending class constructors can’t exactly be used to make a movieclip instance in Flash. Those movieclips are only made by Flash itself as commanded by the timeline or through the use of dynamic movieclip creation functions like duplicateMovieClip or attachMovie. So what is there to do?

Luckily, Actionscript provides you a method for telling Flash that it may need to use a class other than MovieClip when it creates movieclip instances on the screen. That way every movieclip won’t be restricted to the same default inheritance chain with the direct association to the MovieClip class and you can have your own class pose as a movieclip instance's primary class. The command that allows for this is Object.registerClass.

 

 
 

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
The Text Animation Component for Flash CS3
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.
Check out our high quality vector-based design packs! Flash Effect Components

Flash Templates
CSS Templates
Dreamweaver Templates

flash menus, buttons and components
Digicrafts Components The best flash components ever!
Entheos Flash Website Templates Free Flash Page Flip
flash components Buy and sell FLAs at Ultrashock!
Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com Purchase & Download Flash Components
Learn how to advertise on kirupa.com