# Check MovieClip name by KEY\_DOWN

**URL:** https://forum.kirupa.com/t/check-movieclip-name-by-key-down/290136
**Category:** flash
**Created:** [June 10, 2009, 7:25am UTC](https://forum.kirupa.com/t/check-movieclip-name-by-key-down/290136 "2009-06-10T07:25:18Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Gyan\_Singh](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@Gyan\_Singh](https://forum.kirupa.com/u/Gyan_Singh)
#### Post date: [June 10, 2009, 7:25am UTC](https://forum.kirupa.com/t/check-movieclip-name-by-key-down/290136/1 "2009-06-10T07:25:18Z")

</div>

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…

```auto

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…

```auto

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");

        }
    }
    }
}

```
