ActionScript 3.0 :: Clicking Button Destroys Keyboard Listener?
May 5, 2009
I have a basic presentation which will have basic interactivity for the user. i.e. The user clicks on a play button, and the presentation plays, the user clicks on a back button, and the playhead steps back through the animation. I also want to provide keyboard shortcuts to do the same thing, so the user can also hit the spacebar to play the presentation, or press the left arrow key to step back, etc.
I've successfully gotten both the click interactivity and keyboard interactivity to work... but only separately, when I try to add them to the same file, it breaks. I also think I've figured out why. The problem seems to be that if I click a button that is only on the timeline for SOME of the frames, the KeyboardEvent listener no longer triggers.
I have a rewind button that will jump the playhead to the start of the presentation. However, from a use design standpoint, I really only want the rewind button visible/clickable if the user has advanced a bit into the presentation (i.e. frame 2 or beyond) because having the rewind button active on the first frame of the presentation can be confusing because it makes it appear to the user as though they can still rewind further, even though they've reached the beginning. I want to take a similar approach to a play button... as long as there are frames to play, the play button should be active; however, once you reach the end, the play button should dim down and not be clickable anymore, which serves as a visual cue to the user that they have reached the end of the presentation.
So, previously (in AS 2.0) this was not a problem. On the frame I wanted the rewind button to be "disabled", I would just turn the Button Symbol into a Graphic Symbol which would make it unclickable and remove any script, and then I would dim the Alpha of the Graphic. So, on frame 1, the rewind button would actually just be a transparent Graphic, and then once the playhead goes to Frame 2, it would be a Button symbol that could be clicked.
This technique apparently will break the new event model in AS3. If you look at the FLA I have attached (just change the extension), you can see that when you first "Test Movie"... any keyboard press outputs a trace statement that shows which key was pressed. However, if you hit the play button to play a little of the timeline, and then click the rewind button (instance name of rewind_btn) which jumps the playhead to frame 1 (where rewind_btn doesn't exist, because it's a Graphic now).
Now my Keyboard listener doesn't trigger!
I've even tried testing to see if the KeyboardEvent listener still exists by using the hasEventListener("keyUp"), and it returns as true, so the listener is there, it just doesn't trigger anymore
How would I go about solving this problem? Because I can see this being a huge issue in a more complicated project, because I could see scenarios where you only want certain buttons to exist on certain frames
[Code]...
View 5 Replies
Similar Posts:
May 5, 2009
I have a basic presentation which will have basic interactivity for the user. i.e. The user clicks on a play button, and the presentation plays, the user clicks on a back button, and the playhead steps back through the animation.I also want to provide keyboard shortcuts to do the same thing, so the user can also hit the spacebar to play the presentation, or press the left arrow key to step back, etc.I've successfully gotten both the click interactivity and keyboard interactivity to work... but only separately, when I try to add them to the same file, it breaks.I also think I've figured out why. The problem seems to be that if I click a button that is only on the timeline for SOME of the frames, the KeyboardEvent listener no longer triggers.
I have a rewind button that will jump the playhead to the start of the presentation. However, from a use design standpoint, I really only want the rewind button visible/clickable if the user has advanced a bit into the presentation (i.e. frame 2 or beyond) because having the rewind button active on the first frame of the presentation can be confusing because it makes it appear to the user as though they can still rewind further, even though they've reached the beginning. I want to take a similar approach to a play button... as long as there are frames to play, the play button should be active; however, once you reach the end, the play button should dim down and not be clickable anymore, which serves as a visual cue to the user that they have reached the end of the presentation.
So, previously (in AS 2.0) this was not a problem. On the frame I wanted the rewind button to be "disabled", I would just turn the Button Symbol into a Graphic Symbol which would make it unclickable and remove any script, and then I would dim the Alpha of the Graphic. So, on frame 1, the rewind button would actually just be a transparent Graphic, and then once the playhead goes to Frame 2, it would be a Button symbol that could be clicked.
This technique apparently will break the new event model in AS3. If you look at the FLA I have attached, you can see that when you first "Test Movie"... any keyboard press outputs a trace statement that shows which key was pressed. However, if you hit the play button to play a little of the timeline, and then click the rewind button (instance name of rewind_btn) which jumps the playhead to frame 1 (where rewind_btn doesn't exist, because it's a Graphic now).
View 10 Replies
Apr 1, 2011
I have a drop-down menu that stays open when I click it, until I click it again. I want it to close when I click away from it. So I created an event listener of type MouseEvent.CLICK and apply it to the stage.
The obvious problem is, though, that when I click the drop-down menu to make it open, I'm also clicking the stage, which prevents it from opening.
I think there's probably a simple solution to this but I'm stuck. I called stopPropagation() on the drop-down menu and that seems like it should help but it doesn't.
View 2 Replies
Jun 10, 2010
Any way to change a keyboard listener I have set up, so that instead of reacting instantly when it hears a key_UP event, it waits to see if there's another KEY_UP within, say 50ms?
View 1 Replies
Oct 11, 2011
I want to monitor each charachter in a text box when a user inputs, eg. there name. If they type John, I want an image to dislplay J . o . h. n under the text box. I cannot seem to figure out how to monitor each letter individually. I could only get it working if i use seperate input boxes, so a input box for j, o, h & n as an example.Could someone point me in the right direrection. Here is the code Im trying to use at the moment.
Code:
////////////////111111////////////////////
firstname.addEventListener(KeyboardEvent.KEY_DOWN, key_pressed);
[code].....
View 1 Replies
Jan 29, 2010
I am trying to write a keyboard event listener so that when I press a specific key it controls the time line. Below is working code for when I press "enter". How would I make it work if I pressed "Q"?
[Code]...
View 3 Replies
Oct 10, 2011
I was trying to make a tank game in which I can move the tanks, let them shoot each other, etc... I insist on creating external classes with Flash Pro cause I am used to OOP language like Java. I created a Tank class which represents all the tanks. Here is the code of this class:
[Code]...
The problem is that the action listener seems never get called when I press any keys. the trace() is not called. But I tried to add a mouse listener just to test and it worked. So I guess its the Keyboard event listener class's problem? Everyone I see on the web uses stage.addEventListener(KeyboardEvent.KEY_DOWN, move) approach.
View 1 Replies
May 3, 2010
Just using the script below to output the key that is pressed in the output but I get the "Cannot access a property or method of a null object reference." warning on the addEventListener line, which I assume is because of the "stage" var. How do I correct that?
Code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="#123456" creationComplete="init();">[code].............
View 9 Replies
Aug 25, 2011
I have a flash app that I would like to listen for a string of characters being typed on a keyboard. If a user typed in apple as an example that would either be correct or incorrect, and if they typed it in uppercase or lowercase or upper and lower it would still equate to true. Here is the tricky part, the string is not being typed into a textfield or anything like that, it must just be typed and after flash sees the correct keys pressed in the correct sequence it will fire a function.
I have seen this done before in a situation where a website had a background administration application, and when browsing the site you could just type admin, and a window would pop up asking for a username and password, so that is almost exactly what I want. Because of this I figured I would try to replicate the admin application first as it should be simpler
This is what I have thus far
stage.addEventListener(KeyboardEvent.KEY_DOWN, keysPressed);
var keyCatcher:Array=new Array(); var keyCatchNew:String;
function keysPressed(e:KeyboardEvent):void{
if(e.charCode==65 || e.charCode==68 || e.charCode==77 || e.charCode==73 || e.charCode==78 || e.charCode==97 || e.charCode==100 || e.charCode==109 || e.charCode==105 || e.charCode==110){
keyCatcher.push(String.fromCharCode(e.charCode));
[Code] .....
View 4 Replies
Mar 1, 2009
Can I use a generic Event listener for both mouse and keyboard ?Something like this ?
Code:
private function controlAction(e:Event):void {
if (e is KeyboardEvent) {
[code].....
View 1 Replies
Aug 24, 2009
I'm trying to creat an "icon carousel", that slides across in the direction given by a keyboard input (arrow keys).
[Code]...
(icon refers to whatever instance name I chose for the specifc icon/layer)
View 10 Replies
Nov 23, 2011
I'm having what's probably a very basic problem, but I keep getting this error message: Error 1079: Label must be a simple identifier. I'm trying to have AS navigate through a panorama I made in photoshop and turned into a movieclip (panorama_mc). I want it to move from end to end (registration point is in the center) without going past the end of the photo on either side. I also want to make sure that when you get to the end, you can navigate back in the other direction.
[code]...
View 11 Replies
Jul 5, 2011
The keyBoard event listeners call on the rotate and unrotate functions and based on the key inputs(A and D) will implement either of the functions and rotate the image or return it to the original upright position. However, I haven't been able to get the function to work. When I press the A or D keys on the keyboard nothing happens. I even put trace() in one of the functions to see if the function will even be implemented but I don't get anything. I put in my Scripts below. Why are the functions not working? Do the eventlisteners fire or are there conflicts? I'm not getting any error messages.
ti.border = true
ti.addEventListener(TextEvent.TEXT_INPUT, onInput);
function onInput(event:TextEvent):void {
if(ti.text.search('a')!=-1) load_image("http://i54.tinypic.com/anom5d.png", "ottefct");
[code]....
View 1 Replies
Sep 6, 2009
Is there a reason why a keyboard event listener would not work if the flash is embedded in an HTML? The rest of my game is running fine in the background, but I can't launch the movieClip "nextCar." My code is below, if that makes any difference...
function goNow (event:KeyboardEvent): void { thisOtherKey = event.keyCode; if (thisOtherKey == 32) { nextCar.gotoAndPlay(2); parkingQue.play(); tries++; }}stage.addEventListener(KeyboardEvent.KEY_DOWN, goNow);
View 2 Replies
Jul 5, 2011
I have this keyboard event listener to listen for key_Down of letter A and D but I end up with and error:
1119: Access of possibly undefined property A through a reference with static type Class.
When I use
function rotate(evt:KeyboardEvent):void
{
if (evt.keyCode==68) {
evt.currentTarget.rotation = 90 }
[Code].....
View 2 Replies
Jul 6, 2011
The keyBoard event listeners call on the rotate and unrotate functions and based on the key inputs(A and D) will implement either of the functions and rotate the image or return it to the original upright position. However, I haven't been able to get the function to work. When I press the A or D keys on the keyboard nothing happens. I even put trace() in one of the functions to see if the function will even be implemented but I don't get anything. I put in my Scripts below. Why are the functions not working? Do the eventlisteners fire or are there conflicts?[code]...
View 1 Replies
Jan 28, 2010
I have two scenes in flash - when you go to scene 2 there is a eventListener attached to the stage to move a movieclip. When I test the movie the only way the keyboard listener seems to work is if I click on the stage first, then the object will move. Is there a solution to this. The code I am using is:
[Code]...
View 5 Replies
Sep 23, 2009
Atm im putting a a game i build into my main flash app.Everything works fine except the keyboard listener.unny.AFTER a mouse click on the 'loaded' swf the keys 'arrow UP' + 'arrow DOWN' start working.I created already a script that loads the listeners IF they are not loaded yet, but i think thats not the problem. Same situation.After clicking on the movie it starts to work, but apparently the listeners are already applied. All other listeners work besides the keyboard listeners.Stand alone(the game swf running by its own) the game works perfectly!btw the game is importing a main document class.
Code:
this.addEventListener(KeyboardEvent.KEY_DOWN
var keybListenerLoadedUp:Boolean = false;
[code].....
View 3 Replies
Feb 16, 2009
I made a huge swf video game that involved buttons with [code]I put a data grid on the stage on one frame.It never even enters on stage and this still happens.Make a button and plop a data grid down. publish, delete, publish again.I've done some research and found that I am not the first person this has happened to. My file is basically destroyed and I'm on deadline.
View 4 Replies
Feb 8, 2010
I use a dual-boot computer, with one partition for Linux (Debian) and one for Windows XP. I can't use Flash on Linux as Adobe has never ported it to that platform. So I put my Flash on the Windows partition.Unfortunately, while I have no trouble with Flash 8 on the Windows partition, when I attempt to open Flash 9 on it it crashes the entire system.
My husband found an article in the Winter 2009-2010 issue of 2600, the Hacker Quarterly magazine; it seems that in CS3, which Flash 9 is part of, Adobe has written its copy protection code in such a way as to cause a dual-boot machine to become unbootable after one uses Adobe software.I don't understand all the technical issues, but as the article states, "even though you have paid Adobe real money for their software, they will still potentially ruin your dual-boot system."
I realize Adobe doesn't consider Linux users numerous enough to accommodate,but by taking my money for their product,the company has an obligation to give me value in return.The value I expect is to be able to use the software I paid for - it's not up to Adobe to decide which OS I should use.At least they could warn people that you can't use CS3(and probably not CS4) on a dual-boot system.I will now start learning to use Inkscape immediately.
View 1 Replies
Nov 11, 2011
i have to generate a button dynamically... and have to keep a click handler for the same how to write script for clicking buttonim using following code for creating button dynamically
var btn:Button = new Button;
btn.label = "Print";
View 2 Replies
Nov 24, 2006
I have many buttons (symbols). This is what I want it to do: -Select a button on the screen, and then a movieclip plays. - If the user selects any OTHER button on screen, a message box displays a message.
View 2 Replies
May 22, 2011
I want to stop the sound loop from one button by clicking new button. Does anyone know the code that would stop one button's sound from looping by just clicking another button (for another sound)?So you have these buttons:button 1 button 2 button 3 button 4and after clicking "button 1" a sound loops. when i click "button 2" i want the sound from "button 1' to stop.
View 2 Replies
Jan 17, 2010
how to do so by clicking on the button movieclip moved to x = 100; and when pressed repeatedly to x =- 150 event onRelease - not work:
[Code]...
View 9 Replies
Mar 29, 2009
Now I have 2 movieclip. Mc1 & mc2. I planned to to make mc2 do certain animation and user must input the key within the progress animation of the mc2 in order prevent something happen
View 1 Replies
May 18, 2011
I am using actionscript 3 to make a point and click game. On frame 1 there are two buttons, button 1 and 2. On frame 3 there are two buttons, button A and B. I want it so that after I click button 1 on frame 1, button A on frame 3 will be hidden or when I click button 2 on frame 1, button B on frame 3 will be hidden. The buttons that are hidden do not do anything when you click them.
View 2 Replies
Jul 8, 2011
I am doing this inside a module containing viewstacks and their childs.Calling onInit() on creationComplete of module.When I am inside one of the childs of a viewstack of this module and press Enter, it doesnt not invoke the listener function at all (bp inside this does not get hit).
private function onInit():void{
this.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
}[code]..........
View 2 Replies
Dec 28, 2005
Is there any way to create a keyboard shortcut using a the control button plus a key button. For example, if I want to print the screen, I would press control + p.
View 5 Replies
Oct 18, 2009
ive made a button and ive got it to randomly move to a different position on the screen.the probelm is when i click, everything else on the stage moves. They are all on different layers.How do i get different buttons to only move when i click on them, otherwise they stay where they are
View 1 Replies
Sep 15, 2009
Hi! I just figured out how to animate a button on mouse over. My question now is, how could I make a button animate after clicking it and before it goes to the link?
View 5 Replies