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!

 
Jan
25
2010

Lab: Autopsy of Skinner's collision detection in AS3

Attention: open in a new window. Print

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.

   
Jan
19
2010

Collision detection methods, hitTest and hitTestObject alternatives

Attention: open in a new window. Print

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.

   
Jan
10
2010

Bit shifting and masking, bitwise operators in AS 3. Getting Alpha channel out of the color.

Attention: open in a new window. Print

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.

   
Nov
21
2009

Flash CS4 slow and unresponsive

Attention: open in a new window. Print

I have recently upgraded my operating system to Windows 7. After installation of Creative Suite 4 (when there was nothing else installed except Antivirus and Winamp) I started Flash as a first application to continue working on one of my projects. Sadly I noticed that everything is extremely slow, even when typing code, the editor became just unresponsive and came back to life after few seconds... Everytime when clicking on any of the buttons from Flash panels, there was about 2-3 seconds delay.

   
Oct
19
2009

TIP: Setting the class path permanently for all Flash projects

Attention: open in a new window. Print

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.

   
Jun
23
2009

Passing values from website URL (GET method) to Flash

Attention: open in a new window. Print

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).

   
Apr
20
2009

Using filters from Action Script level

Attention: open in a new window. Print

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.

   
Apr
19
2009

The "Full browser screen" Flash project with tweening

Attention: open in a new window. Print

"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.

   
Mar
25
2009

Colors in Action Script. What is the alpha channel value of transparent pixels?

Attention: open in a new window. Print

ActionScript uses a 32-bit hexadecimal numbers...

 

   
Feb
28
2009

Two ways of preloading in Action Script 3

Attention: open in a new window. Print

Preloader is one of these things that are essential when building a Flash project that will be published on the internet. Firstly, it prevents from playing before all its content is loaded. Without it, animation could start without some of the movie clips on the scene. Secondly, it informs users how long they need to wait before downloading is complete, so they either can close the browser and search for some other content that loads faster (worst case scenario Laughing) or they can wait few more seconds to experience your great work. There are two ways of preloading your content, you can create "internal" preloader for a movie clip itself (should I call that selfpreloader?) or you can create one swf file - loader that will load another swf file - your main project.

 

   
Jan
05
2009

Example of recursive function to trace the display objects

Attention: open in a new window. Print

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.

   
Nov
23
2008

How to create a custom Event that will also pass an argument?

Attention: open in a new window. Print

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.

   
Oct
26
2008

How to change tint of the Movie Clip from Action Script?

Attention: open in a new window. Print

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.

   
Oct
10
2008

getURL in Action Script 3

Attention: open in a new window. Print

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.

   
Sep
07
2008

What's the best practice to use keyboard in your flash games?

Attention: open in a new window. Print

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.

   
Jul
26
2008

Getting a list of frames and frame names in the Movie Clip

Attention: open in a new window. Print

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.

   

AS3 Tips