Copy link to clipboard
Copied
I have a public var called enemyNumber in my Enemy class.
And in my document class, I added an instance of the Enemy class, and I want to give enemyNumber a number. Let's say 1.
Enemy:
//ENEMY HOLDER
public var addMonster:MovieClip = new MovieClip();
public var enemyNumber:int;
//LIST OF ENEMIES
private var croak:Croak = new Croak();
private var worm:Worm = new Worm();
if (enemyNumber == 1) { addMonster = croak; }
if (enemyNumber == 2) { addMonster = worm; }
addChild(monster);
Main:
public var enemy:Enemy = new Enemy;
addChild(enemy);
enemy.enemyNumber = 1;
Basically I added movie clips of enemies that will equal addMonster depending on the number. I want to declare the number in the main document class because I added an instance of the Enemy class in my main. Problem is, when I try this out, nothing is added. The enemyNumber is 0 when I trace it in Enemy class, but 1 when I trace it in Document class. Is there anyway to relay the value of what I have for enemyNumber in my Document class to the Enemy class?
When you first create the instance is the only time those two if statements will execute, if at all. At that point in time it will not have been assigned a value.
You will need something in the main file that causes execution of the conditional(s). You could place them inside a function in the Enemy class and then have the main file call upon that function as needed.
Copy link to clipboard
Copied
The only reference you have to the enemy instance is the instance you create in the main file. In what way are you trying to access its enemyNumber without going thru the instance that you created in the main file?
Copy link to clipboard
Copied
Right. I'm trying to access enemy's enemynumber variable from main file and declare it in main file. But I'm thinking that, since I have an if statement checking to see what enemyNumber equals in my Enemy class, it's not registering the main file declaration.
Perhaps I might need to add those enemies like croak and worm in my main file?
Copy link to clipboard
Copied
When you first create the instance is the only time those two if statements will execute, if at all. At that point in time it will not have been assigned a value.
You will need something in the main file that causes execution of the conditional(s). You could place them inside a function in the Enemy class and then have the main file call upon that function as needed.
Copy link to clipboard
Copied
Worked like a charm! THANKS!!!
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now