Archive for August, 2006

AS3 JSONDecoding Class

Saturday, August 26th, 2006

I added a simple JSON decoding class to the ActionScript 3 source code page of my blog today. This is a useful base class which you can extend to use a JSON object as a data source.

The JSONDecoder class defines a simple set of methods for loading a JSON encoded object from a specific URI, decoding the result into an ArrayCollection of ActionScript Objects, and displaying any errors that may occur.

JSON (JavaScript Object Notation) objects are a lightweight data-interchange format which are very useful due to the fact that they are language independent. JSON objects are simple objects comprised of name / value pairs which are easy to use with any language such as C, C++, C#, Java, JavaScript, ActionScript etc.

AS3 DeepCopy Utility Class

Thursday, August 17th, 2006

In ActionScript 3 when you create an object and set it’s value to that of an existing object, both the new object and the original object point to the same reference. This is known as creating a “shallow copy” of the original object. In a shallow copy, only a reference to the original object is created rather than creating a copy of the object directly.

For instance if you were to do the folowing:

var objA:Object = {id: “Object A: Original ID”};
var objB:Object = {id: “Object B: Original ID”};
var arrA:Array = new Array(objA, objB);
var arrB:Array = arrA;
objA.id = “Some new value”;
trace(arrA[0].id);
trace(arrB[0].id);
outputs:
“Some new value”
“Some new value”

As you can see in the example this can potentially cause problems if you need the indices in the array to not reflect changes in the objects in which they reference. In order to resolve this we would need to make what is known as a ‘deep copy’ of the objects in the Array. In a deep copy the objects that are being referenced are copied to a new memory location rather then pointing to the location of the reference objects themselves.

I wrote a simple class that uses a ByteArray to create a deep copy of the original objects. So if you wanted to create copies of the original Objects you could do so as in the following:

var objA:Object = {id: “Object A: Original ID”};
var objB:Object = {id: “Object B: Original ID”};
var arrA:Array = new Array(objA, objB);
var arrB:Array = DeepCopy.clone(arrA);
objA.id = “Some new value”;
trace(arrA[0].id);
trace(arrB[0].id);
outputs:
“Some new value”
“Object A: Original ID”

Below I have provided a link to view the source code.

DeepCopy

What Adobe is Trying to Accomplish with Flash

Friday, August 11th, 2006

As quoted by Mike Downey in Wired:

“What we’re trying to do with Flash is create a feature-rich run time that’s consistent across all of the platforms. That’s something that has not been the reality for other web technologies. Browsers have not been consistent — even the Java Virtual Machine is rarely consistent on different platforms. For the past 10 years, we’ve been able to say, ‘Here is a technology and a set of tools that allow you to create content once, then deliver it to a wide variety of platforms and know that it’s going to work consistently.”

Flash 10 Year Anniversary

Friday, August 11th, 2006

As many of you may know Flash’s 10 year anniversary is this month and what a great time to be a Flash Platform Developer it is. I have been using Flash Professional 9 alpha these past few weeks and it is without question the greatest release of Flash to date, thanks to ActionScript 3.0.

There are some really good sites out there celebrating the 10th Anniversary of Flash and if you have time you should definetly check some of them out and review the history of this legendary technology. A good article is the one featured in Wired on August 8th. You can view the video from the Adobe Anniversary party here or learn more about the history of Flash from Adobe by clicking here.