“Be inspired, enjoy your work, keep learning and never forget to play.” — gskinner

Where is as2 _root in as3?

Posted: October 27th, 2008 | Author: Ivan Valadares | Filed under: Actionscript3, Best Practices, Code | 8 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. :)


Flex Bindings in AS3 Projects

Posted: July 29th, 2008 | Author: Tiago Bilou | Filed under: Actionscript3, Tutorial | 44 Comments »

Since 99.9% of the work we do is Flash, we pretty much use flex builder to develop Actionscript Projects. One of the things I really wanted to have was bindings. Here's how to use Flex Bindings in Actionscript only projects.

Remember that the Flash framework (textfields, movieclips, sprites, etc) doesn't dispatch the data-binding event. This means that pretty much the only things you can bind are variables.

Make sure you add the flex framework.swc to your project Library Path to have access to the mx.binding.util class.

ChangeWatcher:

Acts like the watch on AS2. It watches a variable for changes and when something happens fires an event. Make sure you call the canWatch to ensure that you can watch it!

There are 3 ways to specify the second parameter, the chain.

  1. A String containing the name of a public bindable property of the host object.

    ChangeWatcher.watch(this, "myvar", handler)

  2. An Object in the form: { name: property name, access: function(host) { return host[name] } }. The Object contains the name of a public bindable property, and a function which serves as a getter for that property.

    ChangeWatcher.watch(this, { name:"myvar", getter: function():String { return "something" }}, handler);

  3. A non-empty Array containing any combination of the first two options. This represents a chain of bindable properties accessible from the host. For example, to watch the property host.a.b.c, call the method as: watch(host, ["a","b","c"]

BindingUtils.bindProperty

Works pretty much the same way as the watch, but instead of having to handle and event it allows you to immediately bind two properties one-way.
The first two parameters are for the the target, the second parameters are the triggers.

BindingUtils.bindProperty( this, "va1", this, "var2");

you can also use the same syntax for the chain.

References:

Language References
Another Tutorial


Convert string date to Date type

Posted: July 16th, 2008 | Author: Ivan Valadares | Filed under: Actionscript3, Code | 1 Comment »

var d:Date = new Date(Date.parse(MM/DD/YYYY));

Christmas day
var d:Date = new Date(Date.parse(12/24/2008));


Get difference between two dates in days

Posted: July 16th, 2008 | Author: Ivan Valadares | Filed under: Actionscript3, Code | 3 Comments »


Dreaming in Flash at The Tech Labs

Posted: July 7th, 2008 | Author: Idoru | Filed under: Actionscript3, Adobe AIR, Dreaming in Flash, News, Papervision3d, Tutorial | Tags: , , , | 15 Comments »

We're proud to announce that Dreaming has published a few tutorials over at The Tech Labs, these tutorials are exclusive and can be accessed at: http://www.thetechlabs.com/

They include an air contact manager, and two sound equalizer how-tos with one of them showing how to get those cool pv3d equalizers.

Enjoy!


As3 Flip Vertical and Flip Horizontal

Posted: June 11th, 2008 | Author: Ivan Valadares | Filed under: Actionscript3, Code | 14 Comments »


CopyPixels With flip vertical and flip horizontal arguments

Posted: June 9th, 2008 | Author: Ivan Valadares | Filed under: Actionscript3, Code | 2 Comments »

This function is like the copyPixels method from the bitmapdata class but let you flip horizontal and/or vertical the bitmapData.

Example swf

Example fla


Insert Thousands Delimiter using RegExps in Actionscript

Posted: May 28th, 2008 | Author: Tiago Bilou | Filed under: Actionscript3, Code | Tags: | 7 Comments »

Today I spend a considerable amount of time trying to change this (10000000) into this (10.000.000). Because I don't think anyone should have to go throught the same ordeal here's a little function that will do it for you.

References:


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 »


“SecurityError: Error #3015: Loader.loadBytes() is not permitted to load content with executable code.”

Posted: May 14th, 2008 | Author: Ivan Valadares | Filed under: Actionscript3, Adobe AIR, Code | 5 Comments »

In the last month I thought Adobe had protect the loadBytes method from the loader so that only “regular” files like mp3, jpg, etc could be loaded, lots of good library’s like Benjamin Dobler wav reader stop working. What I think it is that in last version of flash player Adobe turn allowLoadBytesCodeExecution to false. If you see Adobe documentation they have written “Note: This API is likely to be replaced in a future release of AIR.” If anyone knows what really happen let me know. Now the good part, to solve that is simple, you only need to set allowLoadBytesCodeExecution to true.