I am fooling around with a game, and teaching myself AS2 OOP as I go. I am running into some problems though. I pass my hero class a MovieClip, the problem is that I can’t get or change the depth of the movie clip. so my tiles are ontop of it. It is very possible that I am not doing something correctly. When I try to trace the depth it outputs “undefined,” and nothing seems to happen when I swapDepths.
class Hero{
public var name:String = "none";
private var guy:MovieClip;
private var speed:Number = 6;
private var spacing:Number;
function Hero(n:String, s:Number, obj:MovieClip){
name = n;
spacing = s;
guy = obj;
}
function get _speed():Number{
return speed;
}
function set _speed(nuSpeed:Number):Void{
speed = nuSpeed;
}
function followMouse():Void{
var x1 = _root._xmouse;
var y1 = _root._ymouse;
var x2 = guy._x;
var y2 = guy._y;
var delt = (y1-y2)/(x1-x2);
var deg = Math.atan(delt)*180/Math.PI;
if (x1>x2) {
guy._rotation = deg;
} else if (x1<x2) {
guy._rotation = deg + 180;
}
}
function keytrap():Void{
if(Key.isDown(Key.LEFT)){
moveit("left");
}else if(Key.isDown(Key.RIGHT)){
moveit("right");
}
if(Key.isDown(Key.UP)){
moveit("up");
}else if(Key.isDown(Key.DOWN)){
moveit("down");
}
}
function moveit(dir:String):Void{
if(dir=="left"){
guy._x-=speed;
}else if(dir=="right"){
guy._x+=speed;
}else if(dir=="up"){
guy._y-=speed;
}else if(dir=="down"){
guy._y+=speed;
}
}
function get _col():Number{
return Math.ceil(guy._x/spacing);
}
function get _row():Number{
return Math.ceil(guy._y/spacing);
}
}
I would really appreciate any help. Thanks