Flash Components      Flash Menu      Flash Gallery      Flash Slideshow      FLV Player      Flash Form      MP3 Player      PhotoFlow      Flash CMS      3D Wall      Flash Scroller

Flash / AS



ASP.net / PHP






  Design & Effects
  Audio & Video
  User Interface





Building Protoypes
         by ilyas usal

This totally rocks. Once you start using it, you wonder how you can have missed it for so long...
Basically, a prototype is a function, but the difference is that you can apply it to an object. This is where the fact that Flash Actionscript is Object Oriented is the most obvious. Let me explain.

In a normal function, if you want to apply it to an object, you have to put the object as a parameter of the function. Like this:

myFunc = function (target,parameter1,parameter2) {//...;}

The object concerned isn't really put forward. Now in Object Oriented Programming, what is the most important? The object, yes, and all the functions (called methods) "belong" to the object. For instance, the method attachMovie has 2 syntax:

// usual syntax, the target (myClip) is a parameter
// Aha! The object calling is put in front

You see? In the first case attachMovie is called as a function, in the second case it is called as a method of the object myClip, which belongs to the class MovieClip. It is Object Oriented!!

Now the beautiful advantage of prototypes is that they allow you to add methods to an object, whatever its type (MovieClip, Array, Object...). Let's seen an example with a simple function that traces the name of a clip:

myFunc = function (target)
     trace (name);
// Calling the function
myFunc (myClip);

MovieClip.prototype.myProto = function ()
     trace (name);
// Calling the prototype

In prototypes (and functions), the use of this is constant, because you have to define a function that has to work with any object of a given type, so when you have to it or to one of its properties, you have to use this.

For examples, you can check the following tutorials:

  • Create a photo gallery
  • Random movement in Flash MX
  • Springs: Elasticity, Physics, and Flash MX
  • Flash MX: Making the Prototype Work
  • Hope this tutorial helped. If you have any questions, please post them on the forums at //www.kirupa.com/forum/


    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 menus, buttons and components Digicrafts Components
    The best flash components ever! Entheos Flash Website Templates
    Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com Purchase & Download Flash Components
    flash components Free Website | Make a Website
    Streamsolutions Content Delivery Networks Learn how to advertise on kirupa.com