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

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()); } } }

Join the PC World newsletter!

Error: Please check your email address.

Tags gamesflash

Our Back to Business guide highlights the best products for you to boost your productivity at home, on the road, at the office, or in the classroom.

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

Sam Hampton-Smith

Digital Arts Magazine
Show Comments

Essentials

Microsoft L5V-00027 Sculpt Ergonomic Keyboard Desktop

Learn more >

Lexar® JumpDrive® S57 USB 3.0 flash drive

Learn more >

Mobile

Lexar® JumpDrive® S45 USB 3.0 flash drive 

Learn more >

Exec

Audio-Technica ATH-ANC70 Noise Cancelling Headphones

Learn more >

Lexar® Professional 1800x microSDHC™/microSDXC™ UHS-II cards 

Learn more >

HD Pan/Tilt Wi-Fi Camera with Night Vision NC450

Learn more >

Lexar® JumpDrive® C20c USB Type-C flash drive 

Learn more >

Budget

Back To Business Guide

Click for more ›

Most Popular Reviews

Latest News Articles

Resources

GGG Evaluation Team

Michael Hargreaves

Dell XPS 13

I’d happily recommend this touchscreen laptop and Windows 10 as a great way to get serious work done at a desk or on the road.

Aysha Strobbe

HP Spectre

Ultimately, I think the Windows 10 environment is excellent for me as it caters for so many different uses. The inclusion of the Xbox app is also great for when you need some downtime too!

Mark Escubio

Lenovo Yoga

For me, the Xbox Play Anywhere is a great new feature as it allows you to play your current Xbox games with higher resolutions and better graphics without forking out extra cash for another copy. Although available titles are still scarce, but I’m sure it will grow in time.

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.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?