Hi Friends,
I have some movieclip (ball_1, ball_2, ball_3… so on) randomly moving on the stage.
I have another movieClip named “myBall” moving with arrow keys.
when i press “SPACE” and “myBall” hit other movieclip (ball_1, ball_2, ball_3… so on) I want to trace the name…
I did this with MouseEvent.CLICK like this…
this.addEventListener (MouseEvent.CLICK, checkNum);
function checkNum (evt:MouseEvent):void {
var checkN = evt.target.name;
trace (checkN);
if (checkN == "ball_2") {
trace ("u r right");
}
}
but How can i do this with KeyboardEvent.KEY_DOWN
I wrote code for keys…
stage.addEventListener (KeyboardEvent.KEY_DOWN, go);
function goRight (evt:Event):void {
if (evt.target.x < (moveArea.x + (moveArea.width -30))) {
evt.target.x += xSpeed;
goingL = false;
goingR = true;
}
}
function goLeft (evt:Event):void {
if (evt.target.x > moveArea.x +40) {
evt.target.x -= xSpeed;
goingL = true;
goingR = false;
}
}
function go (g:KeyboardEvent):void {
if (g.keyCode == Keyboard.RIGHT ) {
myDash.removeEventListener (Event.ENTER_FRAME, goLeft);
myDash.addEventListener (Event.ENTER_FRAME, goRight );
}
if (g.keyCode == Keyboard.LEFT ) {
myDash.removeEventListener (Event.ENTER_FRAME, goRight);
myDash.addEventListener (Event.ENTER_FRAME, goLeft);
}
if (g.keyCode == Keyboard.SPACE ) {
// here i want to trace movieclip name which is hitting and then
if (myDash.hitTestObject(ball_2)) {
trace ("Yes !! u r right");
}
}
}
}