help.
Hi, i am having an very weird problem in as3:
i am having 2 different codes in 1 scene, this should be ok i think, but only 1 of the 2 codes are working,
i am having 1 code for scrolling background.
and 1 code for moving an animation with arrowkeys ( keyboardevent )
but only the scrolling background is working, and when i am removing the scrolling background code, the keyboardevent is working perfect.
I am only in able to use 1 code, the other is not working, but both codes are correct, i tried to add gotoAndStop, but that didn't work too.
when i have both codes in as3, my animation ( with the keyboardevent ) disappears, it is not in the scene anymore.
does anyone knows how to fix it??
code:
var goDown:Boolean = false;
var goUp:Boolean = false;
var goLeft:Boolean = false;
var goRight:Boolean = false;
function hearKeyDown(yourEvent:KeyboardEvent):void{
if (yourEvent.keyCode==Keyboard.RIGHT){ goRight = true; }
if (yourEvent.keyCode==Keyboard.LEFT){ goLeft = true; }
if (yourEvent.keyCode==Keyboard.UP){ goUp = true; }
if (yourEvent.keyCode==Keyboard.DOWN){ goDown = true; }
stage.addEventListener(Event.ENTER_FRAME, moveCube);
}
function hearKeyUp(yourEvent:KeyboardEvent):void{
if (yourEvent.keyCode==Keyboard.RIGHT){ goRight = false; }
if (yourEvent.keyCode==Keyboard.LEFT){ goLeft = false; }
if (yourEvent.keyCode==Keyboard.UP){ goUp = false; }
if (yourEvent.keyCode==Keyboard.DOWN){ goDown = false; }
stage.removeEventListener(Event.ENTER_FRAME, moveCube);
}
function moveCube(evt:Event):void {
if (goRight){ cube_mc.x+=5 };
if (goLeft){ cube_mc.x-=5 };
if (goUp){ cube_mc.y-=5 };
if (goDown){ cube_mc.y+=5 };
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, hearKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, hearKeyUp);
cube_mc.gotoAndStop("albertj");
var scrollSpeed:uint = 1;
//This adds two instances of the movie clip onto the stage.
var s1:ScrollBg = new ScrollBg();
var s2:ScrollBg = new ScrollBg();
addChild(s1);
addChild(s2);
//This positions the second movieclip next to the first one.
s1.x = 0;
s2.x = s1.width;
//The speed of the scroll movement.
//Adds an event listener to the stage.
stage.addEventListener(Event.ENTER_FRAME, moveScroll);
//This function moves both the images to left. If the first and second
//images goes pass the left stage boundary then it gets moved to
//the other side of the stage.
function moveScroll(e:Event):void{
s1.x -= scrollSpeed;
s2.x -= scrollSpeed;
if(s1.x < -s1.width){
s1.x = s1.width;
}else if(s2.x < -s2.width){
s2.x = s2.width;
}
}