Tuesday, February 5, 2008

Flash AS3 -- keylistener problems

Here is an odd one. Using Flash CS3 I am trying to capture keystrokes. But I have not been able to make it work when testing the movie within Flash -- the key press is only registered once and a while. Instead I find that the focus tends to go to the Flash CS3 interface itself (causing the tool bar to change items instead) So, I need to test the behavior by opening the .swf directly.

BTW, the forward and back buttons work fine--but the character keys are very buggy.

Very wierd. I must be doing SOMETHING wrong?

2 comments:

ErikSternberger said...

Hi, I was pulling my hair out on this today as well!

I think it is not an AS3, but a CS3 issue, since I was having to use AS2.

If I tried to trace an "A" the Flash interface would select the Arrow tool from my toolbar.

I think this is an issue with how CS3 puts the Flash Windows on top of the exported Flash. It automatically defaults to the Flash menu system instead of the export.

I just created a dynamic text box on my main timeline and set a fake trace to that box to track my keystrokes as I develop my current piece so I can test it outside of Flash, where it seems to work perfect.

Hope that helps!

Brian said...

Hi Erik,

That makes sense and is a good workaround. Speaking of which I had another issue in the same project -- I had a world map which zoomed in on different countries in sequence and I needed to be able to to allow the user to "jump" to that country if needed. I wanted the user press "Ctrl", then the country code (ie. "arg" for argentina)and then "Enter". But I found that unless I had a dynamic text field hidden offstage that stored the code as a string, flash didn't seem to be able to keep track of it--even though I was assigning the code to a string. Anyway, I should go back and document that one too, it was very annoying ;-)

Anyway, I'm glad you found your answer and best of luck on the project!