hi all,
i’ve been searching the answer for the last couple days for this one.
my question is probably easy but i don’t have any idea what i should do for i’m new in as3. please kindly give me your guidance.
-
I have a fla. There’s only one instance on the stage. it is a small circle named “me”
-
Then i have a class within “com.myClass” folder.
here’s the script:
[AS]package com.myClass{
import flash.events.Event;
import flash.events.KeyboardEvent;
public class Character {
var keyUP:Boolean = false;
var keyDOWN:Boolean = false;
var keyRIGHT:Boolean = false;
var keyLEFT:Boolean = false;
var power = 2;
var friction = 0.7;
var xspeed = 0;
public function Character() {
trace("called");
stage.addEventListener(KeyboardEvent.KEY_UP, key_Up);
stage.addEventListener(KeyboardEvent.KEY_DOWN, key_Down);
me.addEventListener (Event.ENTER_FRAME, myFunction);
}
function key_Up(event:KeyboardEvent) {
switch (event.keyCode) {
case 37 :
keyLEFT = false;
break;
case 38 :
keyUP = false;
break;
case 39 :
keyRIGHT = false;
break;
case 40 :
keyDOWN = false;
}
}
function key_Down(event:KeyboardEvent) {
switch (event.keyCode) {
case 37 :
keyLEFT = true;
break;
case 38 :
keyUP = true;
break;
case 39 :
keyRIGHT = true;
break;
case 40 :
keyDOWN = true;
}
}
function myFunction (e:Event) {
if (keyUP) {
trace("Up");
}
if (keyDOWN) {
trace("Down");
}
if (keyLEFT) {
xspeed -= power;
}
if (keyRIGHT) {
xspeed += power;
}
xspeed *= friction;
me.x += Math.round(xspeed);
}
}
}[/AS]
now, this script give me:
“1120: Access of undefined property stage.”
and
“1120: Access of undefined property me.”
Then i’m stuck with what to do next.
So my question is:
How do you target my instance in fla with the name me? and also the stage?
I thank you for your support in advanced.
ps.: attached is the files