Next Question
RSS
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.
Permalink | Report
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.
Permalink | Report
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);
}
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)
- In Web Development |
- |
- Report |
-
Share
RSS
Best Answer Chosen by Asker
| January 04, 2009 06:00 PM |
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.
Permalink | Report
Other Answers (1)
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.
Permalink | Report
Answer this Question
Related Questions
No questions found.
Ask a Question
Buy Mahalo Dollars with Credit Card or PayPal
Top Members
Most Popular Tags
Categories
- Anonymous
- Arts & Design
- Beauty & Style
- Books & Authors
- Business
- Cars & Transportation
- Consumer Electronics
- Coupons Deals
- Education
- Entertainment
- Environment
- Fitness
- Food & Drink
- From Email
- From Iphone
- From Twitter
- Health
- History
- Hobbies
- Home & Garden
- How Tos
- Humor
- Jobs
- Legal
- Local
- Love & Relationships
- Mahalo Answers Community
- Money
- Music
- News
- NSFW
- Parenting
- Pets
- Science & Mathematics
- Services
- Shopping
- Social Science
- Society & Culture
- Sports
- Technology & Internet
- Travel
- Video Games
Welcome New Members
- tommayer, November 10, 2009 08:08 PM
- zmillers, November 10, 2009 08:01 PM
- jama808, November 10, 2009 08:00 PM
- mdonovin, November 10, 2009 07:56 PM
- eharmonyblog, November 10, 2009 07:52 PM
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