Parameters AS3 Class

Custom class dependencies: None

This class can be described best as an indexed Object. This means that all the properties may also be accessed through an index, as well as directly calling the property name. It is just about as open-ended as a class can get while still maintaining some kind of a structure. It is dynamic , but also extends Proxy in order to control the properties. It is not a dictionary, and it is not an array, but a kind of mix between the 2.

The most important aspects of this class are the closed properties of ‘length’ and ‘properties’.

The ‘properties’ getter function returns an Array of all the current enumerable properties within the Parameters instance. This is an indexed array, where each item is an Object containing 2 properties of ‘name’ and ‘value’. The ‘name’ property on the Array item represents the name of the property on the Parameters instance. The same goes for the ‘value’ property.

The ‘length’ getter function simply returns the length of the Array received by the ‘properties’ getter function.

With these 2 major functionalities in place, the flash_proxy overrides are fairly simple to figure out. Enumerating over all the properties is now possible through not only the ‘for in’ and the ‘for each in’ loops, but also the ‘for’ and even the ‘while’ loops. By using the ‘length’ property you may enumerate the Parameters instance like it was a regular indexed Array even though it is simply a dynamic Object.

The methods are also tools to allow adding and removing properties much faster:

  • addParam – adds an enumerable property to the Parameters instance with the provided name and value.
  • clear – clears all the enumerable properties on the Parameters instance.
  • addObj – transfers all enumerable properties from the provided Object to the Parameters instance.
  • add – may be provided any number of objects which are all added with the ‘addObj’ method.
  • The flash_proxy methods have also been overridden so properties may be added to the Parameters instance dynamically.

Here is some source to use as an examples:

import com.jidd.utils.Parameters;

var obj:Object = {}
obj.objProp1 = 'value1';
obj.objProp2 = 'value2';
obj.objProp3 = 'value3';
obj.objProp4 = 'value4';

var arr:Array = []
arr['arrKey1'] = 'value1';
arr['arrKey2'] = 'value2';
arr['arrKey3'] = 'value3';
arr['arrKey4'] = 'value4';

var params:Parameters = new Parameters(obj, arr);

params.individualProp = obj;
params.individualProp2 = arr;
trace('TESTING - '+params.individualProp2['arrKey1']);

trace('FOR EACH IN LOOP');
for each(var param in params) {
    trace(param);
}

trace('FOR IN LOOP');
for(var prop in params) {
    trace(prop+' = '+params[prop]);
}

trace('FOR LOOP');
for(var i=0 ; i
    trace('params['+i+'] = '+params[i]);
    trace(params.properties[i].name+' = '+params.properties[i].value);
}

This class is of course has been pretty helpful on its own, but truthfully I created it to be the base of other classes that will be posted at a later time.

Comment if you have any questions, or suggestions.

Comments

3 responses to “Parameters AS3 Class”

  1. Lorenzo Avatar
    Lorenzo

    very useful !
    thank’s

  2. sahar Avatar
    sahar

    you are the man bro !!!
    exactly what i was looking for 🙂
    10x

  3. […] Parameters AS3 ClassWindowLocation AS3 Class » QueryParameters AS3 ClassPosted by: Jim IsaacsAugust9th2008 […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.