Ask questions via twitter! Message any question to @answers on twitter. We'll publish the question and send you a reply each time there's a new answer.
Next Question

Answered Question

 
M$1 January 04, 2009 04:10 AM

FLASH AS3: Help me determine why this code isn't accepting keystrokes

My code accepts keystrokes as long as I am in debugging mode, but if do a straight test, it stops accepting keystrokes and I never get a "listening!" message. Any ideas why?

Output is:
[object Stage]
listening?
listening! (ONLY IN DEBUGGING MODE)
65 (ONLY IN DEBUGGING MODE)

...
import flash.events.KeyboardEvent
import flash.events.Event
import flash.ui.Keyboard;
import flash.display.Stage
...
public function Start()
{
trace(stage);
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
trace("listening?");
this.addEventListener(Event.ENTER_FRAME, DoFrame);
}

private function KeyPressed(eventx:KeyboardEvent):void
{
trace("listening!");
LastGuess=eventx.keyCode;
trace(LastGuess);
}
Interesting Question?  Yes (0)   No (0)   
RSS
 
 

Best Answer  Chosen by Asker

 
January 04, 2009 06:00 PM
There might be some security or other exception that is preventing it from executing some of your code. When you say running in debug mode, you are probably in CS3 right? Maybe when you test externally you could use the debug version of Flash player which is available on the downloads page. Its different from the normal Flash player version.

Also try creating a sprite or other object, adding that to the stage, specifying position and dimensions of the object, and listening to events on that object.
Asker's Rating:
• You were kind of right. I needed to turn off shortcut processing from the control menu of the flash player when running the movie. That's just SOO obvious. I still don't know why debug mode is different. Perhaps it's a player bug. Anyway, problem solved. Thanks.


Helpful Answer?  (0)   (0)    Tip ilaksh for this answer
Permalink | Report
   Reply  
 
 

Other Answers (1)

Sort By
 
January 04, 2009 07:22 AM
I believe that
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);

creates a listener on this to stage for Event.KEY_DOWN. but stage should never dispatch Event.KEY_DOWN.

Another words... the eventListener declaration has to happen within the object you want to listen for the event, the above code tells this to listen for an event from stage, it doesn't tell stage to listen for an event.

Helpful Answer?  (0)   (0)    Tip cyberangel for this answer
Permalink | Report
   Reply  
 
 

Answer this Question

How tips and payments work

This question has already been resolved. You may add an answer to it but you will not be eligible to win best answer or any associated tips.

Related Questions

No questions found.

Ask a Question


140 characters left
Top of Page
Buy Mahalo Dollars with Credit Card or PayPal

Top Members

This Week All Time
  • buddawiggi
    buddawiggi
    2nd Degree Black Belt
    24886 Points
    M$691.47 Earned
  • cfinke
    cfinke
    2nd Degree Black Belt
    22928 Points
    M$29.75 Earned
  • edwardclin...
    edwardclin...
    Green Belt with a Purple Tip
    1868 Points
    M$48.64 Earned
   See All
 

Most Popular Tags

mahalo(1398)
iphone(449)
music(435)
google(324)
food(290)
beer(267)
online(266)
money(246)
apple(239)
movies(235)
aotd(233)
video(200)
health(197)
free(190)
dog(188)
   See All
 

Categories

Welcome New Members


 
 
Mahalo Dollars are the currency of Mahalo Answers.

Each Mahalo Dollar costs $1.

Once you earn more than 40 Mahalo Dollars, you can request to be paid via PayPal. Each Mahalo Dollar is currently worth $0.75 when paid out via PayPal. Learn More

 
 

Please log in to use this function.