views:

217

answers:

2

I'm creating a game in Flash CS4 and using Actionscrip 3.0

I'm adding all my graphics via my AS3 code. I added my hero (A movie clip instance) in the main game class. In my enemy class (the movieclip) I want to make a generic AI which will check to see how close the hero is to the enemy. I tried various ways but I'm not sure how to properly access the X position of my hero from the code in my enemy movie clip.

I tried accessing it using thing such as: hero.x, GAMENAME.hero.x and parent.hero.x but keep getting errors. I'm not too sure what I need to do here.

A: 

You could check the distance from your hero's x position to his/her enemy.x position.

Try something like this...

var dx:Number = item.x-item2.x; var dy:Number = item.y-item2.y;

if (Math.sqrt(dx*dx+dy*dy) < what_ever_distance) { //do something }

A: 

My question was basically "How do I access my main class that is built when flash makes my project". I still don't know how but I did create a basic enemy AI the same way you would think but instead of controlling it all via the enemy class I had to send values to methods in the enemy class via my main class that was created with my project.

CodeJustin.com