Skip to main content
July 14, 2010
Question

Actionscript and key presses

  • July 14, 2010
  • 2 replies
  • 680 views

Basically Im making a video phone menu. I have several labelled items along the timeline with movies in them. I have some of the keypads keys programmed to goto a certain point by stating the label name along the timeline.

So far so good.

Yet, for some reason, flash "accumulates" the keypress actions as it returns to an earlier point on the timeline. I put traces on them and noticed it would also print out the previous keypress action and would play that action if it goes back past the previous labelled item it was on.

Its a bit difficult to explain and I cant really post the file.

Currently going to a labelled frame is like so:

stage.addEventListener(KeyboardEvent.KEY_UP,fl_KeyboardDownHandler_9);

function fl_KeyboardDownHandler_9(event:KeyboardEvent):void
{
    if (event.keyCode==99)
    {
    trace("3 pressed from Menu");

    SoundMixer.stopAll();
   MovieClip(this.root).gotoAndStop("Directory Screen");
    }

}

So if I press keycode 99, the trace above will show but also the previous trace.

Is there some code that can clear the last used keypress variable or something? This is really frustrating.

Thanks.

This topic has been closed for replies.

2 replies

Inspiring
July 15, 2010

I might be mistaken, but is there any chance that you are adding this event listener more than once?  If the code to add the key listener object ins on a particular frame and you visit that frame repeatedly, you might be repeatedly adding your function fl_KeyboardDownHandler_9 to that particular event.  When you press the key, it will trigger the function several times.

I could be wrong about this and am not really sure how to avoid it.  Maybe Ned has some ideas?

Ned Murphy
Legend
July 14, 2010

I can't say I understand the problem, but for now I can offer that anything you trace while a file is running stays displayed in the output panel.    So every trace that occurs while you are running the file appends to whatever else is traced.

July 15, 2010

I realise it keeps it up on screen, but when I press a key after navigating for a while it itll print extra lines from the previous place Ive been on the timeline. Hope thats clearer?