negush blog

Flash, ActionScript and stuff…

Archive for April, 2009

April-23-09

ActionScript 3.0 and Flex optimization

posted by admin

I’ve just found an article on InsideRIA that is actually a list of techniques and best practices for optimizing ActionScript 3.0 code and Flex applications. This is a must know for AS3 / Flex developers. The article has a list of references – information on which the article was based. I really recommend you reading through those articles and also through the comments to the article. You’ll find there a few more links to optimization articles and some extra notes on the information in the article.

Update: Grant Skinner has also published an AS3 performance tester. You might want to check it out. Oh, and I had another post about an interesting AS3 performance tester application. There’s a wiki page too, created by Joa Ebert, listing some AS3 optimization tips.

April-9-09

Import assets from Library

posted by admin

In ActionScript 2.0 it is quite easy to import movie clips from Library via the MovieClip.attachMovie() function. In ActionScript 3.0 it’s a little bit different. The movie clips (or assets in the Library) don’t have a linkage id anymore. Instead they have class names.

So the way to import a movie clip (or another asset) is to first get a reference to that class specified as class name. This is done using the flash.utils.getDefinitionByName() function. Then instantiate the class and finally add the object to the display list.

Here is a simple example:

1
2
3
4
5
6
7
8
9
import flash.utils.getDefinitionByName;
 
var className:String = "TestClip";
var ClassReference:Class = getDefinitionByName(className) as Class;
var clip:MovieClip = new ClassReference();
 
addChild(clip);
clip.x = 100;
clip.y = 100;

April-6-09

Skinning applications using a single image

posted by admin

A few days ago one of my colleagues showed me this interesting tutorial on how to use a single image as a sprite map to skin an entire application. The idea isn’t new at all, desktop applications use it a lot to change their appearances.

Basically, you have a single large image that contains graphical elements used by the controls of the application. You read the image and extract those graphical elements (bitmap images). This Flash tutorial shows you just how you could do it in Flash: http://flash.tutsplus.com/tutorials/effects/build-a-smart-flash-decalsheet-system/. This is quite interesting and worth going through.