Copy link to clipboard
Copied
-----------------
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.
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ok so I've made a class Monster, and I have my movie object Red_Monster
How would I go about creating the variable so it knows it's both?
The only thing I can think of is linking them together as a .variable of the other.
Example:
var this_monster
this_monster
It just seems a bit slopy, it would be nice to have this_monster know it's both. Is there a way to do that?
(added)
I've gotten Monster to extend MovieClip, and this is working to use it as a movieclip.
Currently trying to change the image of the movie clip in code to Red_Monster. Is there a way to do that?
(added)
Found how to do it, sort of. Change the class linkage name to Monster instead of Red_Monster. I just have to make classes for each movie clip.
(last add, answer for anyone else)
Ok the answer is to create a Monster class that extends MovieClip. Then for each color_Monster they all extend Monster, no other code needed inside each class other then the constructor.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now