It's a good idea to declare them yourself because both you--and more
importantly the compiler--know what every instance is. This may not be 100%
on point, but there is a common problem with upcasting, for example, when
Strict Mode is on. 

Here's a scenario. On the stage, you create a movie clip and give it an
instance name of mc. Then, in the timeline, you say:

    var sp:Sprite = new Sprite();
    mc.addChild(sp);

Then later, relative to the sprite, you say:

    sp.parent.gotoAndStop(2);

The compiler doesn't know that mc is a movie clip, so it gives you an error
saying it only understands it to be a DisplayObject.

You then have to say something like:

    MovieClip(sp.parent).gotoAndStop(2);

to manually cast the display object because upcasting isn't automatic in
Strict Mode. Imagine that in a class, and the confusion could increase. So,
the recommended practice is to declare everything yourself. Something like
this (pseudocode):

var mc:MovieClip = new MyMovieClip();
addChild(mc);
var sp:Sprite = new Sprite();
mc.addChild(sp);
sp.parent.gotoAndStop(2);

Again, this is untested pseudocode just to explain the general idea. I chose
a custom linkage class to make this more analogous to using a custom mc
created in the IDE. The process is the same but, after creating it, delete
it and place it with code--just one of multiple ways of handling a task.


On 3/23/08 8:12 PM, "Omar Fouad" wrote:

> Yeah, But WHY I have to Always Declare them By Myself?

Rich
http://www.LearningActionScript3.com


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to