Learning English Online, Free English Lessons For Everyone
_Sponsors_
___ ______

Game: How to create a simple word game in Flash PDF  | Print |  E-mail
Wednesday, 13 April 2011 17:25

Game: How to create a simple word game in Flash

The aim of the tutorial is to learn how to create a simple word game. You will create an input box which will give different results depending on what is typed. The code for this is quite straight forward and has many uses other than this word game. For example forms and password controls.

Click play and try typing: hen, chicken, rooster, cockerel and also a misspelling.

[tl]Step One: Text Input Box[/tl] 1. With the text tool selected drag out a small text box on the main stage. 2. Go to: Window - Properties

  1. Select:** Input Text **
  2. Select your: Font, Font Style, Size and Colour

  3. Select: **Left/Top Justify **

  4. If your Property Inspector is in collapsed view, click on the down arrow in the bottom right corner of the Property Inspector to expand the panel. If you have an up arrow the Inspector is already expanded.

  5. For line type select: **Single Line **

  6. Input text should be Selectable. You do not need to switch it on as input text is always selectable.

  7. Select: **Show Borders Around Text **

    1. For Variable name type: **answers **

[quote]Important: Do not use an instance name only a variable name.[/quote] 11. For Maximum Characters type: 12

  1. Click on the Character button and select: Only - Lower Case

[quote]Note: If you do not restrict the case to lower case (or capitals) you will find that the input box is case sensitive so if someone types Rooster (instead of rooster) the answer is incorrect.[/quote] When you have finished your Property Inspector should look like this.

[tl]Step Two: Making the Text Input Box Blank[/tl] You do this so that when you play the game the text field is always empty. For example if you get the wrong answer and try again the text field will reset to a blank box.

  1. Place the following action in the frame 1 of the timeline (the same frame as your text box):

    answer = ""; ** Note:** If your text input box is not called answer type the name that you used instead of 'answer'.

[tl]Step Three: Placing the ActionScript in the button[/tl] 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

my button

  1. 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");
    }
    }

[u]Line 1[/u]: on (release, keyPress "Enter") { On the mouse click or if you press Enter on the keyboard and ...

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

[u]Line 3[/u]: gotoAndPlay ("win"); Go to the frame labeled win.

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

[u]Line 5[/u]: gotoAndStop ("boy"); Go to the frame labeled boy.

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

[u]Line 7[/u]: 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.

[tl]Step Four: Creating the additional frames[/tl]

You must create the frames which the buttons go to. These frames should have buttons which bring you back to play area of the game so that the user can try again.

Note the labels in the timeline

You create a frame label by selecting the frame and typing the name into the Property Inspector.

The label 'wrong' has been typed into the Property Inspector

Your word game should soon be working a treat.

Source: http://www.webwasp.co.uk/tutorials/159/index.php

  ________


_____
We have 57 guests online

If you don't see anything in the middle of this page, you may need the latest Flash plug-in.
It only takes a few moments to
Download it FREE at Adobe.com. get adobe Flash player

Teaching English For Kids In Primary School

Stydying English Online For Everyone

Game for Kids


Home || Misterduncan|| Flash Cards || Songs For Kids|| Free Games || Learn English with GOGO|| Teaching English For Childern|| ESL/EFL Kids Course ||
Designed by Learning English Online. Designed by: Free Joomla Theme, mysql. Valid XHTML and CSS.