Hi guys! I'm am new with the AS3 and this is my first thread ever! So grats to me!
I ran into a small problem today when i was coding and was hoping someone could explain to me how to revolve that. So here it goes.
I have three files (no sub-folders) in my folder: test.fla test.as and car.as
All i wanna do is to be able to move my movieclip with arrow keys. But i want that to be coded in class car.as. Cuz for some reason it works perfectly when i write the code in my test.as
here is the code i am using for when it dosen't work:
test.as
Actionscript Code:
package
{
import flash.display.MovieClip;
public class test extends MovieClip
{
public function test()
{
// constructor code
var car:Car = new Car();
addChild(car);
}
}
}
car.as
Actionscript Code:
package
{
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
public class Car extends MovieClip
{
public function Car()
{
// constructor code
x = 200;
y = 300;
addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
}
public function keyPressed(event:KeyboardEvent)
{
if (event.keyCode == 65)
{
x -= 5;
}
}
}
}
Btw when i use MouseEvent.CLICK in car.as for moving the object it works perfectly. So i guess it has something to do with stage not recognizing keypresses or something like that.
Well anyways, I hope you understand my problem. Looking forward for some help! Best of luck!