To display consecutive words from an array on a keypress. Event listeners not working.

I need to display a series of words consecutively on a black background. A new word presented each time the Enter key is pressed (It is necessary that its the same key each time i.e the Enter Key). The words are arranged in an array. I have created a function for each Keypress and a listener. Also, as the previous word is replaced by the next, I have a removeChild() to get rid of the the last word.
I have a removeEventListener set up also, to avoid any problems with the listeners. I have been at this a long time without sucess. It must be a listener problem (i.e I have not got the listeners focussed properly?) or a display problem. It only ever displays one word. Please see below code for the display of two of the words from the array which is called cvcwords. The main problem is that the words do not display one after the other (indeed not at all, except for the first one) when the enter key is pressed. Very much as a powerpoint presentation would, thats the idea anyway. I have just a sample of the code below. any help appreciated.
var cvcwords : Array = ["bad", "mod", "hud", "mit", "sat", "fog", "puc",];
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
                              function modKeyDown(e : KeyboardEvent) : void {
                                        if (e.keyCode == Keyboard.ENTER) {
                                                  removeChild(myText);               // to remove previous word from screen
                                                  myText.text = cvcwords[1];        //to display element one of the array
                                                  addChild(myText);
                                        } else if (e.keyCode == Keyboard.SPACE) { //this is for another seperate option
                                                  myText.text = "try again";
                                                  addChild(myText);
               this.stage.removeEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
                              this.stage.addEventListener(KeyboardEvent.KEY_DOWN, hudKeyDown);
                              function hudKeyDown(e : KeyboardEvent) : void {
                                        if (e.keyCode == Keyboard.ENTER) {
                                                  removeChild(myText);  //to remove previous word from the screen      
                                                  myText.text = cvcwords[2];
                                                  addChild(myText);
                                        } else if (e.keyCode == Keyboard.SPACE) {
                                                  myText.text = "do again";
                                                  addChild(myText);
               this.stage.removeEventListener(KeyboardEvent.KEY_DOWN, hudKeyDown);

Based on what I see of your code, the following is all you might need...
var cvcwords : Array = ["bad", "mod", "hud", "mit", "sat", "fog", "puc",];
var counter:int = 0;
stage.addEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
function modKeyDown(e : KeyboardEvent) : void {
    if (e.keyCode == Keyboard.ENTER) {
        myText.text = cvcwords[counter];      
        counter++;
    } else if (e.keyCode == Keyboard.SPACE) {
        myText.text = "try again";
        addChild(myText);
        stage.removeEventListener(KeyboardEvent.KEY_DOWN, modKeyDown);
When you test this in Flash, in the player you need to be sure to select the Diable Keyboard Shortcuts option found under the Control option in the top toolbar
If you really mean to have them try again, you probably do not want to remove the event listener

Similar Messages

  • How to create an array in one field and have another field display certain elements from that array?

    I am making a form in Acrobat XI pro.
    In one text field, I created an array of several elements. I want other text fields to display certain elements from that array. For instance, one field should display the 3rd element, another field should display the 13th element, etc.
    The Javascript for making the array is very long, and so I don't want to have to re-calculate the array every single time (in order to reduce rendering time when I open the form on an iPad). This is why I'd like to only have to create the array once, and simply refer to it throughout the form.

    What code are you using to update the array currently? Are you completely rebuiding it when an element changes, or just changing specific elements for certain fields? I'm still not sure what exactly you are trying to do, but something like this in a document level script will create your array:
    var myArray;
    // Call 'updateArray' to initialize array
    updateArray();
    function updateArray() {
         // Code here to create/update array
         myArray = new Array();
         myArray[0] = "Value 1";
         myArray[1] = "Value 2";
         myArray[2] = "Value 3";
    Then, for each field that needs to update this array, you can add a call to 'updateArray()' in the appropriate event. This will rebuild the array completely; if you just want to update specific elements, then you can access them directly.

  • Hi my name is Aditya. i am using ipad 2. 2 days ago my ipad fall down from my hand and now its screen is not working it is totally blank but shocking thing is that when i take a screen shot the display came back for 2-3 second. any one like me?

    hi my name is Aditya. i am using ipad 2. 2 days ago my ipad fall down from my hand and now its screen is not working it is totally blank but shocking thing is that when i take a screen shot the display came back for 2-3 second. dose ne 1 have same problem....?

    Anyone have any suggestions? or is everyone else just as clueless as me !

  • After upgrading from 4.6C to ECC 6.0 templates not working in smartform

    Hello,
    After upgrading from 4.6C to ECC 6.0 templates not working properly in smartform, although value is flowing to the point the template is getting called and inside the template there are text elements where placeholders are kept to display the value, when the print is taken there are no values being displayed by the text elements.
    Please note - Text elements doesnot have any conditions present in the condition tabstrip.
    Thanks,
    Abhishek

    Hi,
    After the upgrade, you will have to do the security upgrade.
    Please follow these steps.
    1. Go To SU25
    2. Run step 2A to 2D.
    3. In step 2C, you shall get the list of all the affected roles.
    Click on first role. It will take you to authorizations of that role. Click on the "New" tab there to find the new objects added to the role after the upgrade.
    Note: You can open the same role in the unupgraded system to check.
    4. Provide the access to the required authorization objects.
    5. Disable the unwanted authorization objects.
    6. Generate the profile.
    7. Follow the same steps for all the affected roles listed.
    Please note that you will have a list of new objects added.You need to maintain them inorder to avoid any access issues.
    8. After step 2C, complete 2D.
    Regards,
    Imran

  • TS3276 I can receive emails, but I cannot send emails. This just started happening. I have an iPhone and I can send emails from my phone fine. It's just not working on my Macbook. Every time I try to send an email it goes straight to my outbox. Can anyone

    I can receive emails, but I cannot send emails. This just started happening. I have an iPhone and I can send emails from my phone fine. It's just not working on my Macbook. Every time I try to send an email it goes straight to my outbox. Can anyone help?

    Thank you for heading me in the right direction.  I reset my Mail account for Outgoing Mail Server to outbound.att.net:(customer ID)@att.net (instead of smtp.att.yahoo.com, per Apple's online troubleshooting information).   I'm not sure what "(Offline)" means when it appears at the end of my Outgoing Mail Server (SMTP)??  In the Advanced box I clicked on "Use custom port:  465" and checked "Use Secure Sockets Layer."  Authentication:  Password; I have correct User Name and Password put in.  After doing all this, when I try to send emails again today, they go directly to the Outbox and sit there. 
    What's curious is that my first sent email this morning did go out using the Outgoing Mail Server, smtp.att.yahoo.com: (customer ID)@att.net(Offline) but subsequent emails I tried to send with this server were rejected with the message:  "Cannot send message using the server smtp.att.yahoo.com (etc.).  The SMTP server doesn't support TLS(SSL) on port 587.  Verify your account settings and try again."  That's when I tried resetting my Outgoing Mail Server to outbound.att.net (etc.), as mentioned above, and was unsuccessful in sending out any further emails.  I guess my next step is to contact my email service provider, AT&T, and see if they can help me.  Thanks, again, for taking the time to respond and for giving me your input!  Much appreciated!

  • How do I move aiff files from the viewer to the timeline-it is not working when I try to drag and click or clicking on overwrite or insert in Final Cut Pro 7. Thanks

    How do I move aiff files from the viewer to the timeline-it is not working when I click and drag or when I try to move the files to the overwrite or insert buttons-Thanks.

    hi
    You cannot move audio from the viewer
    Mark your in and out points then in the browser grab hold of the audio tracks icon and drag that to the time line
    PJ

  • Face time from my IPhone 4s to iPad 2 is not working but Tango working.please help

    Hi
    After shifting to my new home, my face time from IPhone 4s to I pad 2 is not working, it shows the sign connecting .......... But never able to connect. On the other hand when I called other person it is working ? Please help

    Where did the photos on the iPhone come from? What is in Camera Roll on the iPhone?
    Have you tried restarting or resetting your iPad and iPhone?
    Restart: Press On/Off button until the Slide to Power Off slider appears, select Slide to Power Off and, after It shuts down, press the On/Off button until the Apple logo appears.
    Reset: Press the Home and On/Off buttons at the same time and hold them until the Apple logo appears (about 10-15 seconds).
    No data will be lost.

  • How to remove passcode from ipod touch 3g  if power botton is not working?

    how to remove passcode from ipod touch 3g  if power botton is not working?

    Use this program to place the iPod in recovery mode so that you then can restore the iPod via iTunes.
    RecBoot: Easy Way to Put iPhone into Recovery Mode

  • HT1491 I purchased an application from the app store and the app is not working,How do I get  a refund ?

    I purchased an application from the app store and the app is not working,How do I get  a refund ?

    First, contact the developer of the app and ask for assistance. Then if you cannot get the problem resolved, go to the following link, explain the reason for your request, including that the developer was unable to solve the problem, and ask:
    http://www.apple.com/support/itunes/contact.html
    Though a refund is not guaranteed, it's possible they'll make an exception for you.
    Good luck.

  • Accidently shut down my Mac Book Pro during Windows 7 installation . When re-starting it says "Press any key to boot from CD or DVD". But keybord is not working . and i have the windows CD inside the drive . Pls hlp me to boot the mac again .

    I have accidently shut down my Mac Book Pro during windows 7 installation . When I re started it it began to say " Press any key to boot from CD or DVD " but the keyboard is not working . So I cannot  boot It and the CD is also in the drive . Please help me  to boot back to Mac book Pro and give me a way to start the key bord .

    Hey rudreshchoubey,
    Thanks for the question. The following resource may help to resolve your issue:
    Boot Camp Installation & Setup Guide
    http://manuals.info.apple.com/MANUALS/1000/MA1636/en_US/boot_camp_install-setup_ 10.8.pdf
    If Windows doesn’t install properly
    Verify that you’re using an original, full version of the 64-bit version of Windows 7 Home Premium, Windows 7 Professional, Windows 7 Ultimate, Windows 8, or Windows 8 Pro.
    Restart your Mac and hold down the Option key until one or more disk icons appear on your screen. Insert the Windows installation disc into the optical drive or insert the USB flash drive with Windows into a USB port on your Mac. Select the Windows installation disk icon, then click the arrow beneath it. Quickly press any key on your keyboard to start the installer. Follow the onscreen instructions to repair or reinstall Windows.
    Thanks,
    Matt M.

  • Last 6 months back brought i pod for 50$, but i came to know that,the product is vintage model, hence no support from apple, now problem is that ipod is not working, and the serial number is edited by host ,can u pls reach me on edited by host

    last 6 months back brought i pod for 50$, but i came to know that,the product is vintage model, hence no support from apple, now problem is that ipod is not working, and the serial number is <edited by host>,can u pls reach me on <edited by host> 

    This is a user-to-user support site not a place to reach techs. You can make a Genius Bar appointment at your nearest Apple Store and see if you can do an out-of-warranty replacement or you can use a 3rd party repair site.

  • HT201304 I can't install any app from apple store. The install button is not working now. Before it was working perfectly had installed many app and I had purchased many app from i-store

    I can't install any app from apple store. The install button is not working now. Before it was working perfectly had installed many app and I had purchased many app from i-store

    If you installed Leopard that is why you can't install Mt Lion. The system Must be running Snow Leopard 10.6.8 to upgrade to Lion or Mt Lion.
    If you only erased the Macintosh HD partition then you left the Mt Lion Recovery HD partition in tact on that system. At startup hold down the Command+r keys to boot to the Recovery HD Partition. From there erase the Macintosh HD partition and then select Reinstall Mac OS X. It should then download Mt Lion and ask you for the Apple ID that was used to purchase Mt Lion.
    The Reason Snow Leopard might not be installing is because of the Recovery HD partition. To get rid of that you must First Re-Partition the drive As One Partition. Then install Leopard then SL (Or Snow Leopard from the start) and then update it to 10.6.8. Once that is done you should be able to log on to the Mac App Store and Re-Download Mt Lion.

  • Accidentally copied microsoft word icon  to desk top.   Now program will not work. Error message says cannot be opened because of problem. How do I re-install ?

    Accidentally copied microsoft word icon  to desk top.   Now program will not work. Error message says cannot be opened because of problem. How do I re-install ?

    Drag the Word icon back to where it belongs.
    Applications > Microsoft Office 2011 > Put Word there.
    I'm assuming you have Office 2011. If you have 2008 there should be a similar location to put Word.

  • I have checked the box "display date and time on the Menu Bar" and it does not work.  Using OS X Yosemite 10.10.2  Anybody have a fix?

    I have checked the box "display date and time on the Menu Bar" and it does not work.  Using OS X Yosemite 10.10.2  Anybody have a fix?

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. Don't use the Safari-only “Guest User” login created by “Find My Mac.”
    While logged in as Guest, you won’t have access to any of your documents or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this behavior; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault, then you can’t enable the Guest account. The “Guest User” login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login, by a peripheral device, by a font conflict, or by corruption of the file system or of certain system caches.
    Please take this step regardless of the results of Step 1.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards, if applicable. Start up in safe mode and log in to the account with the problem. You must hold down the shift key twice: once when you turn on the computer, and again when you log in.
    Note: If FileVault is enabled in OS X 10.9 or earlier, or if a firmware password is set, or if the startup volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to start up and run than normal, with limited graphics performance, and some things won’t work at all, including sound output and Wi-Fi on certain models. The next normal startup may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem?
    After testing, restart as usual (not in safe mode) and verify that you still have the problem. Post the results of Steps 1 and 2.

  • Hi! I've tried to downgrade my iPhone from iOS6 to iOS5. However, it did not work and I also cannot turn on my device. What should I do?

    Hi! I've tried to downgrade my iPhone from iOS6 to iOS5. However, it did not work and I also cannot turn on my device. What should I do?
    It is iPhone4. I used RedSnow to downgrade. Unfortunately, it is not success and it make my iPhone death.
    If you guys have any advice, please kindly let me know.
    Thank you in advance for every answer

    Sorry, the terms of use here prohibit any help. You'll have to go elsewhere.
    Good luck.

Maybe you are looking for