Create a simple Flash game

Tap the power of Flash’s ActionScript capabilities to build a simple game with animated characters.

step08

08. Enter the following code into the EB.as file (you can copy and paste it from the file Step 8 on the cover CD). This code is similar to that for the MO class, but has a few differences we’ll look at in a moment: class EB extends MovieClip { var speed; function onLoad() { _x = 800; _y = Math.random()*490; _xscale = _yscale = Math.random()*80 + 20; _alpha = 60; speed = Math.random()*5 + 5; } function onEnterFrame() { _x -= speed; if(_x < -60) { this.removeMovieClip(); } } }

step09

09. The code we’ve just added sets up a variable called speed that represents how quickly the bubble moves across the screen. When the bubble is first created, we set it to appear off the right-hand side of the screen (at an X position of 800 pixels) and we randomly set the Y position somewhere between 0 and 490 pixels (the height of our movie). We create a random scale and speed for the bubble, then each time the onEnterFrame function runs we update the position of the bubble and if it’s moved out of sight (60 pixels to the left of the screen) we remove it.

step10

10. The bubble is ready to go now, but we need something to make it appear. We’ll use the MO class to do this, as the character is always on screen. Edit the MO.as file, and add a new variable underneath the var movedelta = 10 code as follows: var bubbleCounter = 0; Next, after the code that checks for the arrow key presses (within the onEnterFrame function) enter the following additional code (or get it from the CD file Step 10): bubbleCounter += 1; if(bubbleCounter > 30) { bubbleCounter = 0; _root.attachMovie(“EB”, “EB”+_root.getNextHighestDepth(), _root. getNextHighestDepth()); } } }

Tags gamesflash

Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Sam Hampton-Smith

Digital Arts Magazine

2 Comments

Enzogames

1

Good tut but,

I wish there was another way to make the animations other than Adobes convoluted programs. Maybe its me but llustrator is hell, and flash is infuriating. I figure if I keep plugging away at the flash IDE I'll get it one day. Enough griping good tutorial :)

kockningdahy

2

sanzaki

this is a nicce game

Comments are now closed.

Most Popular Reviews

Follow Us

Best Deals on GoodGearGuide

Shopping.com

Latest News Articles

Resources

GGG Evaluation Team

Kathy Cassidy

STYLISTIC Q702

First impression on unpacking the Q702 test unit was the solid feel and clean, minimalist styling.

Anthony Grifoni

STYLISTIC Q572

For work use, Microsoft Word and Excel programs pre-installed on the device are adequate for preparing short documents.

Steph Mundell

LIFEBOOK UH574

The Fujitsu LifeBook UH574 allowed for great mobility without being obnoxiously heavy or clunky. Its twelve hours of battery life did not disappoint.

Andrew Mitsi

STYLISTIC Q702

The screen was particularly good. It is bright and visible from most angles, however heat is an issue, particularly around the Windows button on the front, and on the back where the battery housing is located.

Simon Harriott

STYLISTIC Q702

My first impression after unboxing the Q702 is that it is a nice looking unit. Styling is somewhat minimalist but very effective. The tablet part, once detached, has a nice weight, and no buttons or switches are located in awkward or intrusive positions.

Latest Jobs

Shopping.com

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?