We are currently working on making some changes in DIF. Soon we’ll have candy for you all! Check back for news!

Where is as2 _root in as3?

Posted: October 27th, 2008 | Author: Ivan Valadares | Filed under: Actionscript3, Best Practices, Code | 5 Comments »

If you remember in as2 we had _root which let us access to methods and variables in the root of the project and refer to absolute paths, I thought that as3 didn’t have _root propriety, but I was wrong. root property can be useful if you want to share some value to all the classes in the project, add events to main class that call methods declared inside the class where we are working on or call generic methods declare in root class.

To use root propriety the class that you are working on most extend a DisplayObject (Sprite,MovieCLip,etc…) because you have to add the class to the parent class. And note, you can’t use the root propriety in the constructor method, because the addChild haven’t been process yet! Well let’s stop writing and see some code:

Main.as

In the Main class I’m declaring a variable named myValue which I did the proper sets and get. I am declaring two classes, in one of them I will set the value at the Main class and in the other I will get that value back. I’m also creating a movieClip just for test purposes.

ExampleClass.as

In ExampleClass I’m setting myValue that is propriety of the Main class with some text and I’m tracing the movieClip that I create in the Main Class.

AnotherClass.as

In AnotherClass I’m tracing the myValue propriety. So the result should be:
[object MovieClip]
This value is inside the Main Class

So it works ok, you only have to be carefull not refer root inside the constructor method, have the certain that you already addChild the class when you are referring to root and that the class extends a display object. If you do that, you can too have access to stage propriety, let’s check the next example:

ExampleClass.as

The result should be or stage width.

Another way to access to main proprieties, methods, etc… is with static members. In the next example I’m declaring a static property in the main class and setting and trace the value of it in the example class.

Main.as

ExampleClass.as

The result should be “Hello Word!”, if you didn’t know this, read some books about object oriented programming and static members.

Another way to do the same thing is to pass the instance of main class as an argument to the other classes.

Main.as

Example.as

There are still another ways to access to the Main class code. I don’t know which techniques are more correct, I usually use them all depending in what I need. I hope I help someone. :)


Frameworks, my take on it

Posted: May 20th, 2008 | Author: Idoru | Filed under: Actionscript3, Adobe AIR, Adobe Flex, Articles, Best Practices, Cairngorm, Frameworks, Mate, pureMVC | 12 Comments »

Flash and Flex frameworks.

Lately I've working on three big projects that would require the usage of a framework, and not wanting to extend my own framework, that consists mostly of accumulated libraries over time, I decided to give the most prominent ones a go.

So I started by checking out what was on the market, I found as-hive, pureMVC, Cairngorm and Mate ( there are a few more but somehow I didn't feel they were mature enough to be used.
Read the rest of this entry »


Swc Image problems

Posted: March 6th, 2008 | Author: Ivan Valadares | Filed under: Actionscript3, Best Practices | No Comments »

Last month I had to run one image sequence with 100 images, so I create a new movie in flash, put every image in every frame, image1 to frame1, image2 to frame2, etc. It ran ok in flash but when I exported it to flex (SWC format) the problem began. Every time I did some modifications to one of the SWC files in the project it started to delay 15 minutes to build. So be careful with the number of images inside a SWC file, it can be very boring.


Actionscript Class Comments

Posted: December 20th, 2007 | Author: nuno | Filed under: Actionscript3, Best Practices | 1 Comment »

I've been gathering some guidelines to writing proper class documentation in Actionscript. This is so basic stuff but anyway it helps to have it written down somewhere. Here's what I have so far as general guidelines:

  • Use ASDoc block comments (Ctrl+Shift+D in Flex Builder).
  • Write in English.
  • Use a $Id$ svn/cvs keyword so everyone knows directly who did the last change on the file.
  • If importing to COM, write an example of usage.
  • Favor the use of getters and setters instead of public vars/const.
  • In the source code use the following order to keep things organized: