Skip to main content
May 26, 2008
Answered

One Class to 500 Movies...

  • May 26, 2008
  • 12 replies
  • 984 views
In as2 I have no problem setting one class to multiple movie clips. However, in as3 it wants me to have a new class name per movie clip.

Example:
Let's say I have 50 state movieclips and I want to set them all to use the class State. I don't have to have to make 50 new classes that all inherit the State class. How would I do this "the easy way" ?
This topic has been closed for replies.
Correct answer
everyone loses. got an answer on kirupa.com

you have to set linkage -> base class. and you have to make sure the class you set extends MovieClip. simple enough.

12 replies

Known Participant
June 2, 2008
One last question about this whole methodology, as I've been laerning design patterns over the past week...

I'm at a point where, as this thread has mentioned, I have some MCs either in the library or on the stage, and each has a base class. So for instance, an MC with the class name "myMC" and the base class "myMCclass."

I instantiate it like this:
var something:myMCclass = new myMC();


QUESTION - I'm using MVC with a composite/component pattern for views, which requires passing the model into the constructor. Is there anyway to pass an argument into the constructor for an MC? The only way I've managed it is by using a setter after instantiating.
Known Participant
June 2, 2008
Thanks for the response kGlad.
I am utilizing 200+ mc's on this. After some more reading over the weekend. I might make them sprites to keep the overhead down.

I think I will create a standard class and have all the lots extend that class so I will have minimal verbage in each lot class.

Thanks again,

kglad
Community Expert
Community Expert
May 28, 2008
you can initialize the class data by passing something in the constructor or using a setter.

but the op wanted to use one class for many different movieclips and not necessarily one class for many different objects that would have varying properties/methods. in that situation, it made sense to have each extend the same base class.
Inspiring
May 27, 2008
midimid,

> Is there any way to batch changing the Linkage... panel?

Yes. Check into something called the JavaScript Flash API (aka JSFL)
... you'll find it under the "Extending" book in the Help panel. The
language is a lot like ActionScript 1.0 -- which is to say, pretty much
JavaScript -- except your document object model (DOM) is a FLA, rather than
an HTML document.


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


Known Participant
May 27, 2008
Is there any way to batch changing the Linkage... panel?

Say I had 50 swfs, each with hundreds of MCs in each of their libraries. Is there any way to loop through the MCs on the stage and "assign" this class without right-clicking each one and changing the Base Class?
kglad
Community Expert
Community Expert
May 27, 2008
you're welcome.
Known Participant
May 27, 2008
Ah - the trick for me was instance names...if I remove the instance names on the stage, it works. Weird....Thanks!!
Known Participant
May 27, 2008
I'm not understanding.

To take your example - if I have 50 states, each separate, named movieclips already on the stage - if I were to change all of their "Base class" in the linkage panel of the Library to something like "classes.State" I would get the 1046 error.

Where is the autogeneration?
kglad
Community Expert
Community Expert
May 27, 2008
correct. but you can let flash generate those class files for you (that contain nothing) and use the same base class for all of them.
Correct answer
May 27, 2008
everyone loses. got an answer on kirupa.com

you have to set linkage -> base class. and you have to make sure the class you set extends MovieClip. simple enough.
Known Participant
May 27, 2008
quote:

Originally posted by: ofeet
you have to set linkage -> base class. and you have to make sure the class you set extends MovieClip. simple enough.


I have to do something similar and I'm a bit confused with your conclusition - it appears that this still requires that each moveiclip has its own separate AS file, otherwise you get error 1046: Type was not found. Correct?