flash actionscript:
Hello, I've been trying to get the keyboard navigation to work with no success. What I want is for users (especially visually impaired) to be able to navigate using right and left buttons to progress through a slide show using Flash MX 2004. These are the instructions I've followed to the letter--what am I doing wrong?! 1. Create an invisible button. 2. Place button instance on stage. 3. Select the instance and open the actions panel. 4. In the Actions panel, enter on(keyPress "<Right>"){ nextFrame(); } This is from Chun and Garraffo's Macromedia Flash Advanced book. It's not an issue of formatting since much of the script is available from the drop-down menus in the Action script panel. Any help would be GREATLY appreciated since I've been struggling with this for weeks (searched many sites, tried many other scripts, etc.). Thanks! Natasha :confused;
I don't know about your sample code. But, try this. var keyListener:Object = new Object(); keyListener.onKeyUp = function() { if(Key.getCode() == Key.RIGHT) { nextFrame(); } if(Key.getCode() == Key.LEFT) { gotoAndStop(_currentframe - 1); } }; Key.addListener(keyListener);
Thanks for replying! I'll give that a try and let you know how it goes. :cool;
Darn it! Still no response when I press the keys when testing the movie. If you have any other suggestions, let me know. I appreciate your willingness to assist :-)
Create a new document and create like 10 frames and enter the above code in the first frame.
Update: Macromedia Tech. Help intervened (Thank you Jenyfer and Cleo!), and they were able to come up with a workable solution for my files. What worked was to insert a blank keyframe into every first keyframe for each layer except for the keyboard navigation layer into which the following action script was inserted: //myvar is used for frame navigation. //initial value is 2 which is the frame 2 of the timeline. _root.myvar = 2; //the keylistener object below must be initiated just once //else another keylistener will be created causing //the keylistener to be triggered as many times as //the number of keylistener object is created. var keyListener_obj:Object = new Object(); keyListener_obj.onKeyDown = function() { trace(myvar); switch (Key.getCode()) { case Key.LEFT : trace("left"); stopAllSounds(); //conditional statement must be used to prevent the //playhead from going back to frame1 or past page1 //and creating a new keylistener object. if (_root.myvar<=2) { _root.myvar = 2; } else { _root.myvar = myvar-1; } gotoAndStop(_root.myvar); break; case Key.RIGHT : trace("right"); stopAllSounds(); //conditional statement must be used to prevent the //playhead from going beyond page 22 if (_root.myvar>=23) { _root.myvar = 23; } else { _root.myvar = myvar+1; } gotoAndStop(myvar); break; } }; Key.addListener(keyListener_obj); So glad for all the help from everyone--thank you! Natasha
Don't see what you're looking for? Try a search.
|