Action Script 3 tips and code snippets
As we all know, human brain is not perfect. It's hard to remember everything, sometimes it's just easier to keep all the things you have learnt in one place and then come there later if necessary. This is why I decided to write some of my notes and snippets here. Then I thought, why not publish it to others? So please feel free to use it and comment if you have any advices or corrections :) Enjoy!
Lab: Autopsy of Skinner's collision detection in AS3
In this article I'm working out the famous Grant Skinner's collision detection algorithm (yes, I know...I don't have any more interesting things to do at the moment :-) ). I will go through the code, line by line, trying to understand the whole process.
Collision detection methods, hitTest and hitTestObject alternatives
Flash has never had perfect solution to detect collisions. HitTest from Action Script 2 has been replaced by two separate methods in Action Script 3: hitTestObject and hitTestPoint. They are very similar to their old brother... they are still not perfect. Fortunately there are few alternative collision detection methods available, I'm going to test them here in this article.
Bit shifting and masking, bitwise operators in AS 3. Getting Alpha channel out of the color.
In this article I'm going to show how to extract color channels out from the color value and how to create new colors using bitwise operators in Action Script. First there is some theory with examples and then practising with coding.
TIP: Setting the class path permanently for all Flash projects
When working with classes, you need to show Flash where to look for them. In order to do that you need to define a class path – which points to the root of the whole organized structure of directories and subdirectories containing your different classes (packages). I used to define a document-level class path – separate for every new Flash project. But there is a way of creating a global class path for all the projects you will work on.
Passing values from website URL (GET method) to Flash
There are plenty of situations when you may need to pass arguments from URL to the Flash. In my case I was looking for a way to change the Flash banner on a corporate front website to display different content for different marketing campaigns. Company runs number of different campaigns for different products, publishing many ads on IT portals. Flash banner on company's website will display different advert according to the parameter in URL that will be passed from these ads. (like http://company.com/index.php?campaign=5).
Using filters from Action Script level
To apply filters from Action Script we use "filters" property of every display object. All the available filters are available from flash.filters package. Example below presents how simple is to apply filter to the movie clip instance. Box is a Movie Clip of square placed in library.
The "Full browser screen" Flash project with tweening
"Full screen" or "full browser screen" Flash websites became a standard on the web now. And it's actually very easy to create such a website as Action Scripts 3 provides us with RESIZE event to track size changes of the Flash Player window or the internet browser. Actually, all we need to do is just adjust x and y properties of our display object or resize any background to fit the resized window.
Colors in Action Script. What is the alpha channel value of transparent pixels?
ActionScript uses a 32-bit hexadecimal numbers...
Example of recursive function to trace the display objects
To use this function, just pass your display object or stage reference to get the list of all display objects sorted in a tree view.
How to create a custom Event that will also pass an argument?
The most convenient way to communicate between objects is to use events. I'll show an example how to create custom event that will also carry a parameter.
How to change tint of the Movie Clip from Action Script?
Applying tint from Action Script is almost as easy as from Flash GUI. All we need to do is to customize setTint property of Color object and then apply it to the Movie Clip's transform property.
getURL in Action Script 3
There is a little more to write when you want to link from Flash to some website. Action Script 2 offered getURL method, Action Script 3 doesn't have it anymore.
What's the best practice to use keyboard in your flash games?
To capture which key was pressed by the user, we use two keyboardEvents KEY_UP and KEY_DOWN. When user presses the key down, KEY_DOWN event is dispatched only once. But what if you want to create a game where to make hero walking or car driving user needs to keep the key down for a longer time. Obviously you don't want user keeps pressing key time after time.
Getting a list of frames and frame names in the Movie Clip
Movie Clip has property called currentLabel that returs an array. We only need to iterate through the table getting frame numbers from .frame and frame names from .name.

