Learn Flash: ActionScript

Home Food Mates • Members Tutorials Forum Buy Templates Contact Us 

 


Flash Tutorials

   

Flash - Word Game

Free Flash Tutorial


Step 3    <<   Previous      Intro   1   2   3   4     Next   >>       >>   Webwasp Mates

 

Step Three: Placing the ActionScript in the button

  1. Place a button next to the text box.
    Either create your own or drag one out of the Button Library: Window > Common Library > Buttons


  2. my button

  3. Attach the following code to the button:

    on (release, keyPress "<Enter>") {
       
    if (answer eq "rooster" or answer eq "cockerel") {
          gotoAndPlay ("win");
       }
    else if (answer eq "hen" or answer eq "chicken") {
          
    gotoAndStop ("boy");
       }
    else {
          
    gotoAndStop ("wrong");
       }
    }

Line 1: on (release, keyPress "<Enter>") {
On the mouse click or if you press Enter on the keyboard and ...

Line 2: if (answer eq "rooster" or answer eq "cockerel") {
If the text input box called answer is rooster or cockerel then ...

Line 3: gotoAndPlay ("win");
Go to the frame labeled win.

Line 4: } else if (answer eq "hen" or answer eq "chicken) {
If the text input box called answer is hen or chicken then ...

Line 5: gotoAndStop ("boy");
Go to the frame labeled boy.

Line 6: } else {
This has not got a (answer = "word") which means that whatever is typed (other than the specified words above) then ...

Line 7: gotoAndStop ("wrong");
Go to the frame labeled wrong

Note: If you have specified lower case as the input text value then the words "rooster", "chicken" etc. must be typed in the code as lower case and visa versa if you have typed them in upper case.

         

Step 3    <<   Previous      Intro   1   2   3   4     Next   >>       >>   Webwasp Mates


Webwasp Community: Webwasp Mates & Dates

Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates

 Top of Page Home Food Mates Members Tutorials Forum Buy Templates Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.