Skip to main content
May 19, 2013
Answered

Can you create a "constructor" for movie clips?

  • May 19, 2013
  • 1 reply
  • 812 views

-----------------

What I'm doing:

var this_array[counter] = new monster; //monster is a movie clip

init_monster(); //set's things like .name, .x, .y, etc.

-----------------

What I want to do:

var this_array[counter] = new monster();

-----------------

When I add a "monster"  I then call a function to "initialize" all of it's stats.

Is there a way in the creation of the object, like with a constructor, where it automatilly does it on 1 line?

I'm teaching myself and am a little stuck on this part.  If I have to create a "monster class" to do what I want just say so.

Any simple examples or links to simple examples would be great. Thanks in advance.

This topic has been closed for replies.
Correct answer Ned Murphy

There is no real difference between these two lines except that the second one is the correct way to write it. 

var this_array[counter] = new monster;

var this_array[counter] = new monster();

In both cases you would need to take some extra action to assign various properties to the object.  You could write a class file that does this, or you could let Flash create the file (by assigning a class linkage in the library) sans the ability to set specific propertiies to specific values.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
May 19, 2013

There is no real difference between these two lines except that the second one is the correct way to write it. 

var this_array[counter] = new monster;

var this_array[counter] = new monster();

In both cases you would need to take some extra action to assign various properties to the object.  You could write a class file that does this, or you could let Flash create the file (by assigning a class linkage in the library) sans the ability to set specific propertiies to specific values.

May 19, 2013

In terms of game speed/efficency, which would require less work for the computer at run time?  Using init_monster() at creation or having the monster class?

Ned Murphy
Legend
May 19, 2013

I don't chase microseconds of processing time like that to see which is faster, so I can't answer it.  If the code does the same processing, it probably doesn't matter how you spread it around.... it will still do the same amount of work to get from A to B.

From a programming speed/efficiency standpoint, having the class be a self-contained vehicle defining an object has little if anything that can compete with it.