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

kglad
Community Expert
Community Expert
May 26, 2008
use a setter if you're instantiating your movieclips in the authoring environment.

all states have some things in common. those common things put in your state class. (for example, they all have a capital city, population etc.)

so, your state class would have a capital property, population property etc. the value of that property (ie, the capital's name, the state's population etc) you might determine in another class that loads an xml file that contains data about each state.

so, each state instance could set the name property of the state instance. and your setter could use that to retrieve data from your xml parsing class and populate the properties of your state which you could retrieve using getters.
Known Participant
May 28, 2008
kglad,
I understand the use of the setter and getter type functions to add common information to the 'states'
But how do you initialize the information, or what ofeet asks about connecting the script to the movieclips or instances.

I will be using this same type of functionality on a community containing information on each lot. I like the idea of storing all the information in an xml file and access when needed. thanks for that insight.
Im currently reading up on xml file access.

I like the idea of having one class handle the main information access on all lots, but adding that to all the movieclips with the linkage option is pretty cumbersome (with 200+ lots), and I now there has to be a more efficient way of adding a class to a stage instance or movieclip at runtime. (besides, I am running into the same brick wall with adding a class to more than one movieclip in the library "thru linkage option". removing all library movieclip instance names is not an option)

I guess what im asking is for a basic outline of the steps necessary.

ie. (b.t.w. i now this is all wrong, but it will give you an idea of my goal.)
on movie initialize
run attach class to all lots specified in an xml file
this xml file will also contain all lot info. ie size, cost, etc..

Im sure this is not the correct angle of attach for this scenario. I would like to see the smartest / most efficient way of attacking the issue.

whewww.

your student










kglad
Community Expert
Community Expert
May 26, 2008
make one state class and pass a parameter in the constructor or in a getter that determines the state's specifics.
May 26, 2008
let's say you drag the state movieclips onto the stage so that you can have them arranged. Once the swf compiles, all these movies have been created and then I won't be able to pass them into my State class. I'm trying to figure out how to do that without working out a "hack"