Académique Documents
Professionnel Documents
Culture Documents
Step 3: Logo
Create a new Flash File and set its dimensions to 320480 px.
Select the Text Tool (T), and choose a cartoon style font, I used GoodDog 86 pt.
Write "Hangman+" and break apart (Cmd+B) the text to add a gradient color.
Select the graphics and open the Color Panel, choose Linear Gradient and use these colors: #FBA31E, #FECB56.
Use the Gradient Transform Tool to rotate the gradient and get a color as shown in the image.
Repeat this process in the "+" using these colors: #831000, #A91101.
Convert the whole lot to a MovieClip and add a Drop Shadow Filter with the following values:
Step 4: Background
Lets create the Background.
Open Photoshop and create a new file (320480).
Select the Gradient Tool (T) and add a brown (#4E4236, #382F26) radial background starting from the center to one
of the edges.
Save your image as png-24 using the "Save for Web & Devices" option in the File menu.
Your background should look like this:
Select the Rectangle Primitive Tool and create a 20050 px rectangle with the same yellow gradient as before
(#FBA31E, #FECB56).
Go to Rectangle Options in the Properties Panel and set the corner radius to 8.00.
Select the Text Tool, create a new Static Text and write "New Game". I used this format: Myriad Pro Semibold, 24 pt,
#831000.
To create a letter press effect, duplicate (Cmd+D) the textfield and move it a pixel down, Change the text color to
#FDDA8A.
Convert it to MovieClip and center it in the stage. Set its instance name to "newGame".
Repeat this process with two more buttons; Options and About. Remember to change the instance names.
Convert what you have so far to a MovieClip, name it "menuScreen" and place it temporarily away from the stage.
As you can see we use the same background, so duplicate it and center it in the stage.
Step 7: NoteBook
Select the Rectangle Primitive Tool, change the corner radius to 10 and draw a 260250 px rectangle. Add a radial
background (#FBEE84, #FDF9B2).
To make the lines, l use the Rectangle Tool and draw a 2601 px rectangle with a color of #C6C970.
Duplicate the line (Cmd+D) and place it 10 pixels down, repeat this until you get something like the following image:
For the side lines, create a 1250 px, #99832E rectangle and and place it 20 pixels from the edge, duplicate it and
place the new one 2 pixels from the original.
Convert this to MovieClip, duplicate it, send it to back and place it 5 px lower. Use the same button filter.
Now well give the notebook a title; this text will change according to the category selected in the Options.
Select the Text Tool, create a 23625 px Dynamic TextField and write some text as a guide. The format is Marker
Felt 18 pt, #663622.
Use the letterpres technique we used before to add some detail. The instance names are "categoryText", and
"categoryLP" for the letterpress field.
Step 8: Hangman
To draw the hangman well cheat a little, since Flash doesnt have brushes or anything similar well use a Font to
draw crayon style.
I used characters from the font LeviCrayola to draw this:
Convert each part to a MovieClip and set their instance names like this: head, body, leftArm, rightArm, leftLeg,
rightLeg.
Place the Hangman parts in the center of the notebook and continue to the next step.
Step 9: Keyboard
The user input will be handled by a keyboard in the stage that will compart the key pressed to the hidden screen.
Select the Rectangle Primitive Tool and draw a 2638 px rectangle with the previously yellow background, add a
corner radius of 5.
Convert the 2 elements to a MovieClip and name it as the Letter it represents in UpperCase.
Repeat this step with all the letters, remember to set the correct instance name.
We will also create a MovieClip that will appear on top of the key when its pressed using the same rectangle created
for the key
Copy and paste the rectangle and change it color to white, alpha 30%, mark the "Export for ActionScript" box and
name it "Inactive".
The Category option, as the name says, describes the type of words that will be displayed when playing. You can use
unlimited number of categories, well see that later in the code.
The Victory option is the number of words that you need to correctly guess to declare the game as won.
The Lives option is the number of wrong answers you can make before you lose the game.
The right ones are Dynamic and fomatted like this: Helvetica Regular, 15 pt, #673723. (add instances in image)
Create another circle, this time 1212, #673723 and center it.
Create a 2px wide 5px tall rectangle and duplicate it, rotate the -45 degrees and break it apart (Cmd+B) to make
them intersect, remove the unwated area to make an arrow, and center it.
Duplicate and place the buttons as shown in Step 11 and name them: "catButton", "vicButton" and "livesButton".
Convert all to a MovieClip, mark the "Export for ActionScript" checkbox and name it "OptionsView". You can delete
the symbol from the stage now.
Create a 320240 px rectangle and use this radial gradient: #000000 alpha 0, #000000 alpha 50.
Next, create a 260100 px white rectangle with 20 px corner radius and place it in the middle of the black
background.
Duplicate the rectangle and make it 25696 px, #FCB73A alpha 90.
Create a 24023 px Dynamic TextField and name it "title". Press the "Align Center" Button in the Paragraph panel
and use the letterpress technique, this time moving the duplicated textfield up. The format is Helvetica Bold 19 pt,
white.
Use another Dynamic TextField with this format: Helvetica Regular 15 pt, white. Place it in the center and use the
Align Center option.
Name it "content" and add some text to the fields as a guide.
Convert all to a MovieClip, mark the "Export for ActionScript" checkbox and name it "AlertView".
The package keyword allows you to organize your code into groups that can be imported by other scripts. Its
recommended to name them starting with a lowercase letter and use intercaps for subsequent words, for example:
myClasses.
If you dont want to group your files in a package or you have only one class you can use it right from your source
folder, but the idea is to be organized.
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.events.MouseEvent;
import flash.events.Event;
/* Import classes for animations */
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
In this example, the HangmanPlus class inherits all the methods and properties of the Sprite Class.
/* categories, the loader funtion will load a text file using the names in
this array
if you want to add a category, just add the text file to the directory
where Hangman+.swf is
and the name of the file to the array */
private var categories:Array = new Array("Fruits","Animals", "Sports");
private var category:int = 0;// This variable will be changed in the Options,
when the user click the More Button 1 is added, then used in the array to
choose the correct category
private var correctLetters:int = 0;//The correct letters guessed, it will be
compared to the letters array length to check if word is complete
private var tries:int = 6;//The number of tries, (head, body, two arms, two
legs)
private var btnSnd:ButtonSound = new ButtonSound();// The sound that will
play when a keyboard button is pressed
private var inactive:Inactive;//The clip that we will use to block the keys
already pressed
private var icontainer:Array = new Array();//An array to store the inactive
clips for effective removal
private var keys:int = 0;//A variable to count the keys that are already
inactive, this var indicates the number of "icontainer" to remove
private var index:int;//Stores the value of the String.search method, used to
search for the key pressed in the word hidden
private var buttons:Array;//The array of buttons names, used to add all the
listeners easily
private var txtLoader = new URLLoader();//This will load the text file
specified
private var allWords:String;//A string with all the words contained in the
text file
private var allWordsArray:Array = new Array();//Containes the allWords var,
separated by word
private var currentWords:String;//The current word(s) to be guessed
private var fmt:TextFormat = new TextFormat();//TextFormat
private var us:Underscore;//The underscore clip
private var usContainer:Sprite;//A container for the underscores
private var letters:Array;//The letters of the current word
private var tf:TextField;//TextField
private var tfCont:Sprite;//Contains the textfields
private var tfs:Array = new Array();Stores the textfields, used to remove
them
private var tween:Tween;//Tween, for animation
private var spaces:int = 0;//Stores the spaces in the current word(s)
private var arrayIndex:int;//Stores the words that have not been used
private var options:OptionsView;// The options view clip
private var about:AboutView;
private var alert:AlertView;
private var correct:int = 0;//The correct words counter
private var fails:int = 0;//Fails counter
private var victory:int = 3;//Default victorys to win
private var lives:int = 3;//Default lives
private var alertIsOnStage:Boolean = false;//True if AlertView is in stage
{
/* Have to declare the new Array in the constructor in order to detect
that the (array) elements are MovieClips in Stage*/
buttons = new Array(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
R, S, T, U, V, W, X, Y, Z);
/* Menu Screen buttons */
menuScreen.newGame.addEventListener(MouseEvent.MOUSE_UP, init);
menuScreen.about.addEventListener(MouseEvent.MOUSE_UP, showAboutView);
menuScreen.options.addEventListener(MouseEvent.MOUSE_UP,
showOptionsView);
/* Create textfields for word */
fmt.color = 0x282425;
fmt.font = "Avenir 85 Heavy";
fmt.size = 18;
hideParts();//Hides the hangman parts
}
addChild(usContainer);
}
rightLeg.visible = true;
for (var j:int = 0; j < letters.length;
j++)//Shows the missing letters
{
if (tfs[j].length == 0)
{
tfs[j].textColor = 0xFF0000;
tfs[j].text = letters[j];
}
}
removeButtonListeners(buttons);
fail();
break;
default :
trace("Error");
}
}
}
array[i].removeEventListener(MouseEvent.MOUSE_UP, onKeyPress);
}
}
tween.addEventListener(TweenEvent.MOTION_FINISH, removeAboutView);
}
private function removeAboutView(e:TweenEvent):void
{
removeChild(about);
}
Conclusion
You have created a fully featured Hangman game in ActionScript 3; add your own categories and enjoy!
I hope you liked this Premium tutorial, thanks for reading!