You are viewing the Articles published in

AS3 Custom Tween API

A few months ago I was experimenting with the new Tween classes available in ActionScript 3.0. After importing the Tween class from the new package I received the following error when I attempting to instantiate a Tween instance
ReferenceError: Error #1069: Property onTweenEnd not found on mx.controls.DataGrid

I found that this error would occur no matter what type of component I attempted to call a Tween on. This error I assume was being called on or during an interval call as it was firing constantly.

So after spending a decent amount of time going back and forth trying different things I simply decided it would be easier to write my own Tween API for AS3. My intentions were to simply provide a basic Tween API for an application that I was developing at work. all I wanted to do was have the ability to easily apply Tweens to a component in Flex 2. I wanted the tween to be simular to that which was available in ActionScript 2 under the mx.transitions packages.

The custom Tween API is easy to use and also very useful so I have decided to distribute it as an .swc file for other Flex Developers to use in their Flex 2.0 Projects.

The Tween API consists of 3 destinct classes:

  1. Tween – Public class which provides all Tween functionality
  2. TweenType – Static class which provides a simple set of public constants for providing Tween types
  3. TweenEffect – Internal Static class which provides all Tweening methods which are from Robert Penner’s Tweening equations

Usage is pretty straight forward. All you have to do is import the Tween and TweenType classes and instantiate an instance of the Tween class. The Tween class constructor excepts 6 parameters which are as follows:

  1. tweenTarget:DisplayObjectContainer,
  2. propertyToTween:String,
  3. tweenType:String,
  4. tweenStartPosition:Number,
  5. tweenStopPosition:Number,
  6. tweenDuration:Number

The second parameter, propertyToTween can be set by using a constant from the TweenType class. This class is useful and enables you to easily see what type of tweens are available via the list of public constants.

Future revisions will include a callback event handler which will fire once the Tween is completed. I will continue to post updates once they are completed.

You can download the Tween API (version 0.1.9) for AS3 by clicking here.

AS3 JSONDecoding Class

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

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

Real-World Flex Seminar in NYC

I will be attending the “Real World Flex Seminar” aptly titled “Next Generation Application Development with Flex” in NYC on August 14th located at the Roosevelt Hotel.

Speakers will include some of the industries leading Flex developers including Chris Coenraets and Jesse Warden as well as many others who are helping to push Flex into the next generation of RIA development.

For more information check out :http://www.flexseminar.com/

The Future of ActionScript (ECMA 4)

The ECMA has released resources to the public reflecting the 4th edition of the standard. Being that ActionScript implements the ECMAScript standard, these future implementations will most likely become part of ActionScript in the future.

Adobe has members on the committee which is evident as many of the new features are following ActionScript 3’s lead (such as strict and standard modes).

The link below is a good starting point to see where ActionScript, not to mention Java, C# and many other languages will be heading in the future.

http://developer.mozilla.org/es4/proposals/proposals.html

Apollo: FAQ

Adobe released the updated FAQ for Apollo last week. If you are not familiar with Apollo, it is a cross-operating system runtime being developed by Adobe. Apollo aplications can be developed using either the Flex framework, Flex Builder, Flash 9, or html and Javascript. It is a standalone runtime that dows not require a browser.

To learn more about this revolutionary runtime from Adobe read the FAQ: http://labs.adobe.com/