stupidlikeafox's Blogs


23,786 Reputation Points (Ranked 2nd)

View My:
Profile | Collection | Games Followed | Reviews | Blogs | Friends | Points

Tutorial: My First Flash Game

Published Friday 27 Feb 2009 5:51pm | 28
Tags: Flash games, tutorials

Heya, Fox here. This tutorial is a basic introduction to a few simple bits and pieces of code in flash - aimed at the utter n00b. If you have flash and have no idea how to use it - and would like to, this is intended for you. This is also my first crack at writing a tutorial, so if you try it out let me know how you went and if you found this helpful. That way I can learn from this experience and write better tutorials in the future. But anyway, let's proceed.

Project: My first Flash Game: A point and click abomination.

Technical stuff:

stop();
frame labels and gotoAndStop()
an introduction to buttons

Description: We'll make a simple ugly game by placing different images onto frames of the main timeline, and use invisible buttons to move between different frames.

Note: This code is written for AS2.0. I can't be bothered learning AS3.0 just yet lol.


------------

 

Step 1: Let's begin!
Open Flash and create a new file (File -> New), and select "Flash File (Actionscript 2.0)". Once your blank doc*ment is open, make four layers in your "Timeline" window by selecting the "Insert Layer" button (see below). Double-click the name of each label to rename them "actions", "labels", "buttons" and "images". It should look like the image below.

img 1

Step 2: My first line of code!
Click the Keyframe on the "actions" layer to select it, and open your "Actions" window. We will be placing a line of code onto the keyFrame. Click inside your actions window, and type the following code:

stop();

When a movie plays, the "stop();" will halt it from going any further, and await any further instruction. By default any timeline will play through, so adding this code will prevent that. Congratulations, you've written your first line of code! (presumeably :P)

yay code!

At this point let's save the file as "game1.fla"

Step 3: Design your game!

For the purposes of this tutorial (and my laziness) I'm going to keep my example VERY simple. You can go as hard out as you want - but for my game I will only have two rooms. The first room will have a window to the west, a *closed* chest to the south, a picture frame to the east and a *open* door to the north. Through the door is another room. This room has a chair to the west, a painting to the north, a locked door to the east, and the door leading to the first room to the south.

(At this stage please note that I will be using this example in following tutorials and building upon it - at the same time introducing you to new bits and pieces of code.)

Step 3: Building your game!
Since I have two rooms, I will need 8 different keyFrames (at simplest, 4 per room). Create 8 keyFrames on the "labels" layer by selecting the eight frames, right-clicking, and selecting "Convert to keyFrames".

select frames

Each keyFrame will have a label which relates to their position and the direction they are facing in your game. For my example, these will be:

Room1_north
Room1_east
Room1_south
Room1_west
Room2_north
Room2_east
Room2_south
Room2_west

To label each frame, select the frame, then in the "Properties" window, enter the respective name. (See below)

making frame labels

Once all frames are correctly labelled, convert the required amount of keyFrames on the "images" layer and add your images! For example, on the Room1_north keyFrame, I will draw a door, Room1_west a window, etc!

Pretty
^K, my rooms are ugly. I'M LAZY!

Step 5: Buttons!
Open your "Library" window and click the "New Symbol" button.

buttons

In the box that appears, name your new symbol "invisible_button", select the "button" type, and hit "OK" to make your new button.

 

You will now be inside the button. Buttons have different states such as up, over and down - but we will only need the "hit" state. Select the frame under "Hit" and create a keyFrame there. Now on the stage, draw a box. That's it! You have just made an invisible button. We will be placing instances of this button on the stage, and giving it some code!

making a button

Return to the main timeline by pressing the "Scene 1" button. On the "buttons" layer, create a keyFrame for each frame used (like you did for step 3). Select the first keyFrame.

 

Click and drag an instance of the invisible button from the "Library" window, and drag it onto the stage. The button should look like the one below.

invisible button

Place this button on the top-left corner of the stage, and make it the full height of the stage. This button will be used to turn the character 90 degrees anti-clockwise. Select the button then open and select your "Actions" window. Enter the following button code:

on(release){
gotoAndStop('Room1_west');
}


Here, I used "Room1_west" because I start at "Room1_north", then turn 90 Degrees anti-clockwise and now the character will be facing west. The code on(release) is a button function that is activated when a user clicks then releases a button. The code gotoAndStop() moves the playhead to a specific frame and stops there. It could be either frame numbers or labels, but for this example we are going to the frame "Room1_west" and stopping there. Yay, you just wrote some more code - and what's better... We can now test it!

left button

Step 6: Test your movie!
Press Ctrl+Enter to test your movie (or select Control -> Test Movie). If it has worked correctly so far, you should be able to click where you placed your invisible movie - which then changes the image displayed to the image on the frame you told it to go to and stop on! If so, we're on the right track!

If not, something is wrong. Here are some common mistakes.
gotoAndStop(Room1_west) - frame labels need to be in quotes.
gotoAndStop('room1_West') - frame labels are case sensitive.
If these are fine, check your target frame's label. Are you sure you spelt it right? (Don't worry if it's still bung, ask any q's in the comments below or pm me :P)


Now add a button to turn right. Do the exact same thing you did for the left button, only place it on the right and change the gotoAndStop target label from 'Room1_west' to 'Room1_east'. Repeat in the center if you want to be able to walk forward (in my case I want to go to he next room) and you have completed your first frame!

3 buttons!

Save. :P

Go to the second frame on the main time line (my label here is "Room1_east") and add left and right buttons like you did for the first frame. Because your user is currently facing "east" (well, in my case they are :P), the left button needs to call "gotoAndStop('room1_north');" and the right calls "gotoAndStop('room1_south');"

At this stage you should get it right? Each frame has the character at a certain position, facing a certain direction - so what do you need me for? Place buttons where they should, and tell the playhead to go to and stop wherever you want. You know how!

Here's my end swf. And here's my end working file. It's pretty ugly, I won't lie to ya. But the fundamentals are there.

Any q's just let me know!

 


Read all of stupidlikeafox's blogs » « Return to Top

 

COMMENTS (28)

You must be logged in to post comments.

Log in to comment or Register now!
Srassy
On Saturday 28 Feb 2009 12:24 PM Posted by Srassy
Cool stuff! I'm pretty terrible at flash so this could be useful. :D
 
 
+ - 0
Reply  
stupidlikeafox
On Saturday 28 Feb 2009 12:32 PM Posted by stupidlikeafox
sweet - if you ever have any q's just let me know man. always glad to help!
 
 
+ - 0
Reply  
Ubercuber
On Saturday 28 Feb 2009 12:43 PM Posted by Ubercuber
Nice tutorial bro. I look forward to some more intermediate stuff..so I can print them out and make a workbook for work...
 
 
+ - 0
Reply  
ChatterboxZombie
On Saturday 28 Feb 2009 2:53 PM Posted by ChatterboxZombie
Ow, my pride.
 
 
+ - 0
Reply  
SmurfWorks
On Saturday 28 Feb 2009 4:40 PM Posted by SmurfWorks
A good start Slaf. It'd be pretty impressive if for example, it had a key frame like resident evil's opening door scenes and it went to there and redirected to the frame you were going through. I'm going to play with this tonight.
 
 
+ - 0
Reply  
tim705
On Saturday 28 Feb 2009 5:50 PM Posted by tim705
I've never used Flash, but I'll download it and try this tut. Cheers brudah.
 
 
+ - 0
Reply  
alienhominid
On Sunday 1 Mar 2009 10:37 AM Posted by alienhominid
I used to muck around with flash a fair bit. Ima reinstall and try this.

Yuss working on bombchain 3 I see.
 
 
+ - 0
Reply  
stupidlikeafox
On Sunday 1 Mar 2009 10:41 AM Posted by stupidlikeafox
1 March 2009, 10:37 AM Reply to alienhominid
I used to muck around with flash a fair bit. Ima reinstall and try this.

Yuss working on bombchain 3 I see.
lol yeah - "BC3_editor.fla" is my map editor, just making stages for it now and it should be sponsored soon!
 
 
+ - 0
Reply  
alienhominid
On Sunday 1 Mar 2009 11:21 AM Posted by alienhominid
1 March 2009, 10:41 AM Reply to stupidlikeafox
lol yeah - "BC3_editor.fla" is my map editor, just making stages for it now and it should be sponsored soon!
I can haz Beta PLzors?
 
 
+ - 0
Reply  
stupidlikeafox
On Sunday 1 Mar 2009 11:35 AM Posted by stupidlikeafox
1 March 2009, 11:21 AM Reply to alienhominid
I can haz Beta PLzors?
lol sure, you want it now or when the rest of the graphics are in?
 
 
+ - 0
Reply  
alienhominid
On Sunday 1 Mar 2009 11:38 AM Posted by alienhominid
1 March 2009, 11:35 AM Reply to stupidlikeafox
lol sure, you want it now or when the rest of the graphics are in?
Um. now please. So it's still in ugly stage right?
 
 
+ - 0
Reply  
stupidlikeafox
On Sunday 1 Mar 2009 11:51 AM Posted by stupidlikeafox
1 March 2009, 11:38 AM Reply to alienhominid
Um. now please. So it's still in ugly stage right?
its not too ugly, just used mostly old graphics. will email...
 
 
+ - 0
Reply  
alienhominid
On Sunday 1 Mar 2009 1:56 PM Posted by alienhominid
1 March 2009, 11:51 AM Reply to stupidlikeafox
its not too ugly, just used mostly old graphics. will email...
KTHANX
 
 
+ - 0
Reply  
alienhominid
On Sunday 1 Mar 2009 9:24 PM Posted by alienhominid
Up to lvl 8 so far it's getting pretty difficult. when will the full game be realeased?
 
 
+ - 0
Reply  
stupidlikeafox
On Sunday 1 Mar 2009 9:52 PM Posted by stupidlikeafox
1 March 2009, 09:24 PM Reply to alienhominid
Up to lvl 8 so far it's getting pretty difficult. when will the full game be realeased?
im just finishing the maps for it then handing it over to the portal to redo the graphics. bounce took ages, but (hopefully) itll be out in less than a month. and yeah, its hard. im trying to figure out my own stages lol...
 
 
+ - 0
Reply  
SaVag3_MiNd
On Monday 2 Mar 2009 1:45 AM Posted by SaVag3_MiNd
nice little noob tut. Ive always liked flash since flash 3 was realeased and even more so when version 5 came out I personally only used it for animation I did how ever make a hand full of side scrolling shooters and platform games for assignments sakes but hey nuff bout me great read.
 
 
+ - 0
Reply  
stupidlikeafox
On Monday 2 Mar 2009 7:45 AM Posted by stupidlikeafox
2 March 2009, 01:45 AM Reply to SaVag3_MiNd
nice little noob tut. Ive always liked flash since flash 3 was realeased and even more so when version 5 came out I personally only used it for animation I did how ever make a hand full of side scrolling shooters and platform games for assignments sakes but hey nuff bout me great read.
cheers man, yeah, i wanted to write something that was slow enough to not be frustrating, yet introduce a couple of key bits and pieces. might do a side-scrolling platformer one, but ease into it.
 
 
+ - 0
Reply  
Ron
On Monday 2 Mar 2009 10:16 AM Posted by Ron
Nice work, great tute!
 
 
+ - 0
Reply  
SaVag3_MiNd
On Monday 2 Mar 2009 2:21 PM Posted by SaVag3_MiNd
2 March 2009, 07:45 AM Reply to stupidlikeafox
cheers man, yeah, i wanted to write something that was slow enough to not be frustrating, yet introduce a couple of key bits and pieces. might do a side-scrolling platformer one, but ease into it.
Well i'll be looking out for that one when you do! and just to think people use to hand code everything web site related and use java applets before flash hit the scene like good old Pete Barr-Watson and Vas Sloutchevsky I believe still has .spa on hand which were from version 2 of flash if i remember correctly. keep on keep'n on!
 
 
+ - 0
Reply  
shadowbandit
On Monday 2 Mar 2009 6:43 PM Posted by shadowbandit
cool... I'll read it more thoroughly if/when I get flash.
 
 
+ - 0
Reply  
Nivicious
On Tuesday 3 Mar 2009 2:27 AM Posted by Nivicious
oh man i cant wait till we start our flash gaming module, saw some of the last class' work and the stuff we eventually learn is crazy awesome

choice idea for a blog!
 
 
+ - 0
Reply  
SaVag3_MiNd
On Tuesday 3 Mar 2009 1:04 PM Posted by SaVag3_MiNd
3 March 2009, 02:27 AM Reply to Nivicious
oh man i cant wait till we start our flash gaming module, saw some of the last class' work and the stuff we eventually learn is crazy awesome

choice idea for a blog!
Great stuff your gonna love it. Theres some pretty awesome code you can write in OOP and AS3
 
 
+ - 0
Reply  
Chaos_Strikes
On Wednesday 4 Mar 2009 3:43 PM Posted by Chaos_Strikes
thats cool!
 
 
+ - 0
Reply  
twisterjamz
On Wednesday 4 Mar 2009 8:40 PM Posted by twisterjamz
my first flash game would have to be that helicopter game how you left click on mouse to make it go up and release to make it go down
 
 
+ - 0
Reply  
alienhominid
On Monday 9 Mar 2009 4:18 PM Posted by alienhominid
4 March 2009, 08:40 PM Reply to twisterjamz
my first flash game would have to be that helicopter game how you left click on mouse to make it go up and release to make it go down
??
 
 
+ - 0
Reply  
Ruptunex
On Tuesday 10 Mar 2009 11:08 AM Posted by Ruptunex
woosh
head
 
 
+ - 0
Reply  
stungaf
On Friday 15 May 2009 4:22 PM Posted by stungaf
you can buy games that are already made, then you can play them.
 
 
+ - 0
Reply  
Ese-Boii
On Thursday 24 Sep 2009 9:31 AM Posted by Ese-Boii
Wow Thats Was high Tek Stuff Bro

Hahaha Keep Iht Up Man
 
 
+ - 0
Reply