AS3-101: Game Development Part 3 – taterboy
October 2nd, 2011 | Filed under: ActionScript 3, Flash, Flash AS2 to AS3, Flex, Games, Tutorials
This tutorial is the third part in a series on game development with AS3. We will pick up where we left of in the last tutorial which can be found here: ActionScript 3 101 : Game Development part 2
In the previous tutorial we made a MovieClip of a ball move back and forth by pressing the left and right arrow keys on the keyboard. We accomplished this through the use of a variables, functions and events. In this tutorial we will continue to modify our existing code by adding a couple new functions and create something that will begin to resemble an actual game.
The Swap:
The first thing we need to do and swap out the ball artwork with a spaceship graphic. The graphic included with the source is the same dimensions as the ball, which was 72 x 72 pixels. You can use the one in the source code below ( just copy it into your project and delete the ball) or build your own.

AS3-101: Game Development part 2 – taterboy
June 1st, 2011 | Filed under: ActionScript 101, ActionScript 3, Flash, Flash AS2 to AS3, Flex, Games, Tutorials
This tutorial is part 2 of the ActionScript 3 101 : Game Development series. For part 1, go to ActionScript 3 101 : Game Development part 1
In part 2, we will continue animating a ball on stage, but this time we will setup keyboard controls so that a user can control the animation of the ball’s x property.
Before we move into the keyboard event listener, we should structure our code to be more organized and flexible. The top of the actionScript is where I like to put all my variables and things that configure how the game runs. As a general rule, any values that are used more than once or could change should be stored as a variable. Notice the left and right bounds for the ball ( 20 and 455) are used more than once, we should change them to a variable to make our code more flexible. Later in this series, we will move some of these variables from the top of the code to an external xml file, this will make your game very tweak-able without republishing from Flash. The secret to flexible code is lots and lots of variables.
New Variables:
var boundsLeft:Number = 20; var boundsRight:Number = 455; var maxSpeed:Number = 10; |
AS3-101: Game Development part 1 – taterboy
April 21st, 2011 | Filed under: ActionScript 101, ActionScript 3, Flash, Flash AS2 to AS3, Games, Tutorials
This series has been taught to a few students over the last couple years with the intention of making it into a video tutorial series, but due to the lack of time and fear that it will never happen otherwise, we are going to have to do this old-school.
The series was originally taught in Flex / Flash Builder, but with so many Flash AS2 developers still learning AS3, this is a great program for new and old developers who want to develop Flash games using actionScript 3. This tutorial series will be focused on the Flash IDE, if you want a Flash Builder version of this series, please request it in the comments below.
Getting Started:
The foundation of any game is providing a way for users to control elements on the screen. At our game’s core is these 4 lines of code.
// 1B function frameHandler(ev:Event):void{ ball.x += 10; } // 1A addEventListener(Event.ENTER_FRAME, frameHandler); |
Detecting Standalone or Plugin Flash Players – taterboy
January 26th, 2009 | Filed under: ActionScript 2, ActionScript 3, Flash, Flash AS2 to AS3, Flex, Tips
Maintaining version control on project files can easily get out of control when saving multiple versions of the same file. One tip is covered in an earlier post about swf based relative urls for flash/flex files. This tip works even if the host file is moved to a different locations. This way we do not need to save a live version and a local build version.
Why would I care which Flash Player type is used?
Some projects, like kiosks, will end up as a Flash Projector or AIR Application. Until the project is finalized and approved we may need to preview the project for our clients on the web. In AS3 some stage methods are only available to the standalone player. Instead of saving two versions of the same project, one to test the Projector functionality and another for online approvals; we can build one multi-purpose file.
Read More »
SWF Based Relative URLs in Flash or Flex – taterboy
January 17th, 2009 | Filed under: ActionScript 2, ActionScript 3, Flash, Flash AS2 to AS3, Flex, Tips
When a Flash/Flex app loads into a browser, all urls for the swf are now relative to the file that is hosting the swf and not the location of the swf file itself. This can create issues between testing the swf locally and viewing it on the live site.
Case Study:
When building a demo to display on this blog I have to create one version with relative urls to distribute as source and a separate sample for preview using absolute urls. This is because of the setup of the blog, some files like the index page display from the root of the blog while all the article files have unique urls based on title and date.
Read More »
Is AS3 Ready For Prime-Time? (part 3) – taterboy
September 27th, 2008 | Filed under: Flash, Flash AS2 to AS3, Tutorials
Targeting Loaded swfs and Streaming
As we move into the Object Oriented mindset, communication between a host and loaded swf can be a little controversial. Though using bubbling events is great for easy plug and play type communication, establishing a direct connection to pass information can be more efficient.
As a comparison, to load an swf into an AS2 project, all you have to do is tell a MovieClip to load an swf and then that MovieClip will take on all the attributes of the loading swf. To access the loaded timeline you use, MovieClip.gotoAndPlay(2);
In AS3 all loaded swfs are loaded into a loader object that is added to a container. To access the timeline of a loaded swf you would use an instance of the Loader Object’s content.
var loadedSwf:Object = Loader.loaderInfo.content; //or var loadedSwf:Object = Loader.contentLoaderInfo.content; //then: loadedSwf.gotoAndPlay(2); |
Here are a few things to keep in mind when communicating with loaded swfs with AS3.
Read More »
Try.. Try.. Try.. Error Supression – taterboy
August 27th, 2008 | Filed under: Flash, Flash AS2 to AS3, Tips
One of my favorite statements is try..catch..finally.
When building web applications, we as developers need to plan for the unexpected. We know the web does not always behave at the same level of consistency for all users. This does not take into account client systems which can compound minor glitches.
There are also times that you need to compile code that is reliant on external variables. If all the conditions are not returned in a valid format AS3, being very strict, will throw an error and not complete the remaining code sequences as intended.
Read More »
Simple Hex Color Changer w/ ColorTransform – taterboy
August 6th, 2008 | Filed under: Flash, Flash AS2 to AS3, Tips
I was first introduced to the ColorTransform class while reading the AS2 to AS3 migration documentation about setRGB(). I was immediately impressed with the features, but intimidated when I saw the constructor and all the offset, color and alpha arguments. I just needed to change the color of something, nothing special, no gradients, no alpha, no space shuttle landings, just a simple hex color change.
So here is a simple color change utility that is a lot closer to what I am used to.
function paint(obj:Object,color:Number):void{ var ct:ColorTransform = new ColorTransform(); ct.color = color; obj.transform.colorTransform = ct; } |
source here
Is AS3 Ready For Prime-Time? (part 2) – taterboy
July 30th, 2008 | Filed under: Flash, Flash AS2 to AS3, Flex, Tips
Is Flex AS3 and Flash AS3 The Same?
It is hard enough to learn a new language, but when you write code using logic based on a method that worked so well in Flex, but now in Flash you are getting errors telling you that the method does not exits. It can get a little frustrating.
In Flex I use the Canvas as a starting point for most components, it inherits properties and methods from Display Object, UIComponent, and Container classes. In Flash we use a MovieClip as our base, which inherits methods and properties from the DisplayObject and DisplayObjectContianer classes.
Read More »
Is AS3 Ready For Prime-Time? (part 1) – taterboy
July 8th, 2008 | Filed under: Flash, Flash AS2 to AS3, Tips
This is the first in a series of posts about some issues with Flash, ActionScript 3 and current work-arounds.
1. Timeline Animation and Scripting:
I could not believe this issue when I ran across it for the first time. I really hope it is a bug. If you have code on the first frame of a timeline, then advance the timeline, the objects on the next frame are not available to your code until the frame after.
This simple code does not work: (place code on frame 1 and place mc_clip on frame 2)
gotoAndStop(2);
mc_Clip.visible = false;
You get an error that says mc_Clip equals null if it did not exist on the first frame.
Read More »