all groups > flash actionscript > march 2005 >
You're in the

flash actionscript

group:

help: passing parameters to a class that extends movieclip


help: passing parameters to a class that extends movieclip funkDaddyFlash
3/11/2005 9:17:03 PM
flash actionscript:
I'm trying to pass initialization values to a class i created that extends
MovieClip, but when I do, the constructor for my class sees the incoming
parameters as undefined. Any ideas?

I have this in my timeline:

this.attachMovie("mcEventNode", "node1_mc", this.getNextHighestDepth(),
{_x:100,_y:100,classID:12});

My library has the mcEventNode set to use my EventNode class.

The EventNode class reads like this:

class?EventNode?extends?MovieClip?{
?????
?????//CONSTRUCTOR
?????function?EventNode(classID:Number)?{
??????????//movieclip?needs?to?initialize
???????????????super.init();
??????????//set?the?incoming?properties
???????????????trace?("Class?=?"?+?classID);

and so on...

the trace returns undefined every time. Anyone know how to grab the values
sent with AttachMovie when extending MovieClip? Thanks!
Re: help: passing parameters to a class that extends movieclip mpetty
3/11/2005 10:01:44 PM
There is an issue with instantiation timing. A constructor is called before the
object is actually instantiated. The constructor itself is what creates the
instance. Attempting to use attachMovie in this case won't work, because you
are attempting to send values to the constructor function before the instance
is created however you're sending it through an instance member (ie you can't
call attachMovie before you have an instance of movieclip or something that
instantiates it).

It's essentially the chicken and egg paradox.

OOD usually says to avoid instance variables passed through the constructor,
instead either use a member function or an "init"er. If you need to be able to
pass values to the constructor, take a look at MM's example of their own work
around UIObject.createClassObject(). You'll notice initObj is their last
parameter.
Re: help: passing parameters to a class that extends movieclip mpetty
3/11/2005 10:04:47 PM
also, just an fyi... movieclips do not have a method called "init". Only
components do, we use this because of the prototype chaining issue with
constructors for multiple inheritance.

super.init() in your case fails because it does not exist.
Re: help: passing parameters to a class that extends movieclip funkDaddyFlash
3/11/2005 10:17:23 PM
Sweet!

Thanks so much for the quick (and correct) reply. I don't come from an OOP background, so I'm learning as I go.

I now officially owe you a beer.

AddThis Social Bookmark Button