May 27, 2009

Create an XMLList using multiple expressions

Filed under: AS 3 — Tags: , — iBen @ 5:42 am

It is actually possible to create an XMLList that meets more than one condition. The way to do this is a bit linear but will works. Each time you compare an XML element with a condition, you are able to follow up the expression with a request. In most cases you would ask for the name of the element or text or attribute, but we can use this to our advantage and keep checking for conditions to return to a list.

consider the usual way to create an XMLList:

myXMLList:XMLList= xml..childElement.(@identification<=3)

As you know my XMLList will be populated with any node that contains an attribute labeled identification that holds a value that is less than or equal to 3.

Now what if i wanted to know what the value was :
myXMLList:XMLList= xml..childElement.(@identification<=3).@identification

this expression will not only populate my list with the following but because i am still on the same index, i can continue to use the current xml node index to retrieve a value, in this case, the current xml Nodes attribute identification which gives me 2.

Utilizing the same method to find out what that value is, we can once again add another condition to choose whether we want to populate our xmlList with the following node.

myXMLList:XMLList= xml..childElement.(@identification<=3).(@identification!=2)

This statement will only push an element into our xmlList that has an attribute labeled identification which must be either 3 or less, but can not be 2.

May 21, 2009


Filed under: AS 3 — iBen @ 6:11 pm

Well this is a very nice addition to the AS family.

An application domain in summation is the area, ‘domain’ in which you have loaded your swf, ‘application’
To ensure that class definitions of the loaded swf are not overwritten, their definitions are locked away in this application domain. Each swf much like referencing root, will always target the domain in which its been loaded into. ApplicationDomain.currentDomain is the equivalent, but it irrelevant, because that is the default location for a swfs definition so no need to reference that each time you reference a class.

But suppose you wish to be able to access a class from the loaded swf. Unfortunately because of the locked definitions, you can not reference the childs class by name, or by package. You have to reference it by: from the applicationDomain in which it resides, then as a Definition using getDefinition as Class. This will target the class in which you seek and you will be returned a reference to this class to do what you wish with it.

final code in which I want to access class Ball() from swf b loaded into swf a is the following
var loaderInfoOfswfb= getLoaderInfoByDefinition(Object(swfb))
var aD:ApplicationDomain= loaderInfoOfswfb.getApplicationDomain
var searchingForClassBall:Class= aD.getDefinition(’Ball’) as Class
var instanceBall:Ball = new Ball()


Filed under: AS 3 — Tags: , — iBen @ 5:56 pm

I was curious at first the possibility of these two events, but that was mainly because I didn’t rely on many events using AS. I would rely with a passed param, or using _resolve to trigger a method on a function etc, there were many ways around using Events if you were not using components.

Also, I haven’t found a lot of literature regarding a proper way of using events without subscribing to the dispatcher itself-this is very discouraging. Many Books could be written on how to use events in AS3 alone and still be too long to carry out in depth every topic.

Anyhow, ADDED, ADDED_TO_STAGE, REMOVED AND REMOVED_FROM_STAGE are object target references that when used within its class, will respond to events that .. you guess it, are triggered when either being added to stage, or added to another displayObject and removed as well.

These are two events that will be very handy when dealing with Garbage collection on removing listeners, or adding them. Consider the following issue, you have a sprite that makes referenec to the stage but does not get added until its parent is added. if your code looks like the following:

var mySprite= new Sprite()
var mySpritesChild= new Sprite()

and you reference the stage in mySpritesChild within the constructor or a method that is called via instantiation, the stage will be a null reference. But if you are listening for the event of being added to the stage and then triggering that method, you will never have to worry about finding a null error.

Powered by WordPress