Yo.
I'm making a RPG with ActionScript 2.0 in the style of "Tales of"-games when it comes down to battles. Currently I have been working on the engine during battles, and I'm having a slight problem.
In the beginning of each battle a random number of enemy object variables are pushed to the "EnemiesToBeAdded" Array, and always when the length of EnemiesToBeAdded is more than 0, it does the following function that adds an instance of an enemy movie clip to the root:
function EnemyAdder() {
for (var i = 0; i < EnemiesToBeAdded.length; i++)
{
//Variable used for the attachMovie in this function
var AddAnEnemy:MovieClip = _root.createEmptyMovieClip(EnemiesToBeAd ded[0].addCommand, _root.getNextHighestDepth());
//Enemy's _x and _y are defined inside the Enemy object
AddAnEnemy._x = EnemiesToBeAdded[0].location_x
AddAnEnemy._y = EnemiesToBeAdded[0].location_y
//Attaches the enemy to the stage. addCommand is a string variable inside the enemy object, that defines //which library object is to be called from the library. The enemy thingie is created to the maintimeline btw.
AddAnEnemy.attachMovie(EnemiesToBeAdded[
0].addCommand, "Enemy", _root.getNextHighestDepth())
//Pushes the added enemy to the EnemiesOnScreenArray, that then later is used in another function to
//check if one of the enemies is dead, and then empties it from the dead ones.
EnemiesOnScreen.push(EnemiesToBeAdded[0]
)
//Deletes the recently added enemy from EnemiesToBeAdded Array
EnemiesToBeAdded.splice(i, 1)
}
}
Okay, that works just fine. An instance of the enemy movieclip is created to the stage in there where I want it to go. But the problem comes in when my character is for example trying to attack. I'm using the following code to determine is the character hitting the enemy during its attacking frame, if yes, it executes an attack function etc.
onClipEvent(enterFrame) {
if (this.hitTest(this._root.Enemy)) {
_root.Attackblahblahblahblah
}
}
...But it appears, nothing happens! I have used "_name" to check the created enemy instance's name on the stage by adding a button symbol inside the enemy movieclip and giving it the following code:
on(press) {trace (this._parent._name)}
...but it gives out "Enemy" (without quotes) like how it should. So I have no idea why the collision check ain't working.
This problem just came up today, as before this day I was making the game by having the enemy already added on the stage, rather than created through "attachMovie".
Does anyone have a clue what's the cause of this?