var dumbXS:Number = 0;
var dumbYS:Number = 0;
var dumbACC:Number = 0.6;
var dumbDEC:Number = 0.92;
public function DumbClass() {
this.addEventListener(Event.ENTER_FRAME, DumbMove);
}
public function DumbMove(evt:Event):void {
//Increases Speed
this.x += dumbXS;
this.y += dumbYS;
//Reference to a MovieClip on stage called "user".
if (user.y < this.y) {
dumbYS -= dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.y > this.y) {
dumbYS += dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.x < this.x) {
dumbXS -= dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.x > this.x) {
dumbXS += dumbACC;
}
///Decrease Speed
dumbYS *= dumbDEC;
dumbXS *= dumbDEC;
}
}
}
I get an error that "user" is an undefined property even though its on the stage any ideas how I can fix this? :crying:
You need to declare it as a public variable first. Also it is a good habit to always add the attributes public and private even Flash does it for you. It helps the compiler and helps you later when you need to debug.
- The right of the People to create Flash movies shall not be infringed. -
Yes the user is a a MC with the instance "user" on stage. The idea is that when ever space is pressed a instance of the class is created on the stage. But from within the class it cannot seem to get the user.x/y value.
Thats how they spawn atm.
PHP Code:
function spawnCircle() {
var screen_side:Number = Math.round(Math.random()* 3);
var DumbTarget:DumbClass = new DumbClass();
//this["dumbTarget" + dumbLoop] = dumbTemp;
addChild(DumbTarget);
if (screen_side == 0) {
DumbTarget.x = -15;
DumbTarget.y = -15;
}
if (screen_side == 1) {
DumbTarget.x = 815;
DumbTarget.y = -15;
}
if (screen_side == 2) {
DumbTarget.x = 815;
DumbTarget.y = 615;
}
if (screen_side == 3) {
DumbTarget.x = -15;
DumbTarget.y = 615;
}
}
I tried
public var user:MovieClip;
and
public var user:MovieClip = new user_lib; (Because user_lib is the AS Esport name for the MC "user")
Fact is I want to be able to tell the class where on stage the MC "user" is but when ever I use user (because that's its instance name on stage) it sees it as an undefined property.
public var user:user_lib;
var dumbXS:Number = 0;
var dumbYS:Number = 0;
var dumbACC:Number = 0.6;
var dumbDEC:Number = 0.92;
public function DumbClass() {
this.addEventListener(Event.ENTER_FRAME, DumbMove);
}
public function DumbMove(evt:Event):void {
//Increases Speed
this.x += dumbXS;
this.y += dumbYS;
//Reference to a MovieClip on stage called "user".
if (user.y < this.y) {
dumbYS -= dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.y > this.y) {
dumbYS += dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.x < this.x) {
dumbXS -= dumbACC;
}
//Reference to a MovieClip on stage called "user".
if (user.x > this.x) {
dumbXS += dumbACC;
}
///Decrease Speed
dumbYS *= dumbDEC;
dumbXS *= dumbDEC;
}
}
}
I heard I have to use a property manager or constructor but I have no idea which either of them are.