# New to AS3 need some help :-)

**URL:** <https://forum.kirupa.com/t/new-to-as3-need-some-help/313968>\
**Category:** flash\
**Created:** [September 15, 2010, 3:33am UTC](https://forum.kirupa.com/t/new-to-as3-need-some-help/313968 "2010-09-15T03:33:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rifts1103](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@Rifts1103](https://forum.kirupa.com/u/Rifts1103)\
**Post date:** [September 15, 2010, 3:33am UTC](https://forum.kirupa.com/t/new-to-as3-need-some-help/313968/1 "2010-09-15T03:33:39Z")

</div>

Hey everyone,

Sorry this is so long I wanted to make sure to explain everything,

I just got into AS3 I know HTML/CSS/PHP/MYSQL so I hoping AS3 won’t be too hard to pick up.

anyway here is some background on the project i’m working on

its a birds eye view

I have a “hero” named character\_mc when I click he moves flawlessly to where I click.

I have a “enemy” his eyes follow my mouse now I’m trying to get his eyes to follow my hero instead.

This code is in my scene 1 : frame 1 time line:

```auto
import flash.events.Event;
import flash.display.MovieClip;
import flash.events.MouseEvent;

character_mc["charAngle"] = 0;
character_mc["moveX"] = 0;
character_mc["moveY"] = 0;
character_mc["walkSpeed"] = 3;

var characterEndMC:MovieClip = new charEndMC();
var arrayOfBarriers:Array = new Array();

function charLoop(event:Event)
{
	if (character_mc.hitTestPoint(character_mc["charEnd"].x, character_mc["charEnd"].y, true))
	{		
		character_mc["moveX"] = 0;
		character_mc["moveY"] = 0;
		this.removeChild(character_mc["charEnd"]);
		character_mc.removeEventListener(Event.ENTER_FRAME, charLoop);
	}
	

	
	for (var i:int = 0; i < this.numChildren; i++)
	{
		this.getChildAt(i).x -= character_mc["moveX"];
		this.getChildAt(i).y -= character_mc["moveY"];
	}
	
	character_mc.x += character_mc["moveX"] + .05;
	character_mc.y += character_mc["moveY"] + .05;
}

function lookAtMouse()
{
	var characterMC:MovieClip = character_mc;
	characterMC["charAngle"] = Math.atan2(this.mouseY - characterMC.y, this.mouseX - characterMC.x) / (Math.PI / 180);
	
	characterMC.rotation = characterMC["charAngle"];
}

function charMove(event:MouseEvent)
{
	lookAtMouse();
	
	this.addChild(characterEndMC);
	characterEndMC.x = this.mouseX;
	characterEndMC.y = this.mouseY;
	
	character_mc["charEnd"] = characterEndMC;
	
	character_mc["moveX"] = Math.cos(character_mc["charAngle"] * Math.PI/180) * character_mc["walkSpeed"];
	character_mc["moveY"] = Math.sin(character_mc["charAngle"] * Math.PI/180) * character_mc["walkSpeed"];
									 
	character_mc.addEventListener(Event.ENTER_FRAME, charLoop);
}

stage.addEventListener(MouseEvent.CLICK, charMove);

```

Now this code (which makes the enemys eyes follow my mouse is located under symbols \> enemy

```auto
import flash.events.Event;
import flash.display.MovieClip;
import flash.events.MouseEvent;

stage.addEventListener("mouseMove", eyesFollow);

function eyesFollow(e:MouseEvent):void {

	var a1 = mouseX.x - eye1.y;
	var b1 = mouseY.y - eye1.x;
	var radians1 = Math.atan2(a1,b1);
	var degrees1 = radians1 / (Math.PI / 180);
	eye1.rotation = degrees1;

	
}

```

I tried to change mouseX and mouseY with character\_mc.x and character.y but I just get errors being new i’m guessing it doesnt know what character\_mc is but I just dont know how to import it to that part of the script

Sorry for making this so long but I wanted to explain everything out

Thanks for th help!
