Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can you create a "constructor" for movie clips?

Guest
May 19, 2013 May 19, 2013

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

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.

TOPICS
ActionScript
773
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 19, 2013 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.

Translate
LEGEND ,
May 19, 2013 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 19, 2013 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2013 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 26, 2013 May 26, 2013
LATEST

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 = new Red_Monster();

this_monster.stats = new 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines