Forum Topic: Instance name not working? (AS2)

(59 views • 2 replies)

This topic is 1 page long.

<< < > >>
None

Shadowii2

Reply To Post Reply & Quote

Posted at: 10/29/09 03:47 PM

Shadowii2 DARK LEVEL 29

Sign-Up: 09/30/06

Posts: 729

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?

Links to my SheezyArt and deviantArt accounts

BBS Signature

None

ProfessorFlash

Reply To Post Reply & Quote

Posted at: 10/29/09 04:07 PM

ProfessorFlash DARK LEVEL 24

Sign-Up: 10/06/07

Posts: 809

onClipEvent(enterFrame) {
if (this.hitTest(this._root.Enemy)) {
_root.Attackblahblahblahblah
}
}

That's your code. Think for a little what you are saying there. Let's say 'this' refers to a mc called 'myguy'. You are saying in the if clause: myguy.hitTest(myguy._root.Enemy). See something wrong with that? You should. You are trying to hitTest a movie clip with something that's inside of itself, lol :).


None

Shadowii2

Reply To Post Reply & Quote

Posted at: 10/29/09 04:15 PM

Shadowii2 DARK LEVEL 29

Sign-Up: 09/30/06

Posts: 729

Hmm, dunno how that ended up there. Didn't notice that "mistake" till now, but that's due to the fact it worked before I started to imply the attachMovie for creating the enemies in the code.

I now removed that "this" from that spefic part, but it's still not responding.

Is there a possibility that the attachMovie slightly alters the instance name for each one it creates?

Links to my SheezyArt and deviantArt accounts

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 07:27 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!