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

Join the newsletter!

Error: Please check your email address.
Rocket to Success - Your 10 Tips for Smarter ERP System Selection

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
Show Comments

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

Ben Ramsden

Sharp PN-40TC1 Huddle Board

Brainstorming, innovation, problem solving, and negotiation have all become much more productive and valuable if people can easily collaborate in real time with minimal friction.

Sarah Ieroianni

Brother QL-820NWB Professional Label Printer

The print quality also does not disappoint, it’s clear, bold, doesn’t smudge and the text is perfectly sized.

Ratchada Dunn

Sharp PN-40TC1 Huddle Board

The Huddle Board’s built in program; Sharp Touch Viewing software allows us to easily manipulate and edit our documents (jpegs and PDFs) all at the same time on the dashboard.

George Khoury

Sharp PN-40TC1 Huddle Board

The biggest perks for me would be that it comes with easy to use and comprehensive programs that make the collaboration process a whole lot more intuitive and organic

David Coyle

Brother PocketJet PJ-773 A4 Portable Thermal Printer

I rate the printer as a 5 out of 5 stars as it has been able to fit seamlessly into my busy and mobile lifestyle.

Kurt Hegetschweiler

Brother PocketJet PJ-773 A4 Portable Thermal Printer

It’s perfect for mobile workers. Just take it out — it’s small enough to sit anywhere — turn it on, load a sheet of paper, and start printing.

Featured Content

Product Launch Showcase

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?