A great innovation introduced with Actionscript 3.0 is to be able to list all objects (including shape drawn at the time) present in a container ( DisplayObjectContainer ). In fact it was now that Adobe introduced this feature. I had always complained about this lack, especially since going to debug the Flash environment was able to carry it out quietly but remained completely inaccessible from code!
In ActionScript 1.0 and 2.0, you could not access some objects, such as vector shapes, drawn in the Flash authoring tool. In ActionScript 3.0, you can access all objects in the display list, either those created in ActionScript that those made with the Flash authoring tool.
This feature is not be underestimated. In previous versions of ActionScript, in fact, biosgnava keep track of objects in an artificial way, board using an array for example. Furthermore, it was still possible to access objects drawn directly into the IDE of Flash. Now you can "scroll" the entire hierarchical tree in a simple and fast identification of objects, and then all the elements that compose it; from TextField to Shape.
Some of the new methods and properties (made available by the object DisplayObjectContainer ) that allow this are:
-
numChildren
Returns the number of children of a container object (DisplayObjectContainer) -
getChildAt()
Returns the child display object instance that exists at the specified index. -
getChildByName()
Returns the child display object that exists with the specified name. If more than one child display object that has the specified name, the method returns the first object in the list of elements.
For example, starting from the root of the movie, the following code gives us the number of objects on the Stage:
1 | this . numChildren ) ; trace (this. numChildren); |
This simple loop lists all the "names" of objects on the Stage:
1 2 3 4 5 6 | : DisplayObject ; // generico var child: DisplayObject / / Generic var i : uint = 0 ; i < this . numChildren ; i ++ ) { for (var i: uint = 0; i <this. numChildren; i + +) { getChildAt ( i ) ; = child containers. getChildAt (s); child . name ) ; trace (child. name); } |
Try to draw something on the stage with glistrumeti drawing provided by the IDE Flash and run this code:
1 2 3 4 5 | : DisplayObject ; // generico var child: DisplayObject / / Generic var i : uint = 0 ; i < this . numChildren ; i ++ ) { for (var i: uint = 0; i <this. numChildren; i + +) { getChildAt ( i ) ; = child containers. getChildAt (s); rotation = 20 ; child. rotation = 20; } |
Great Shape objects IDE also be accessed and modified at runtime, the first thing basically impossible unless they were transformed into MovieClip with an instance name!
Then what is interesting is the ability to identify objects that interest us by the operator is . For example, you can identify an object (or symbol) is the name of the type. Often, when a symbol is created by the runtime library name has no meaning (instance3) and is useful to be able to identify the type:
1 2 3 4 5 6 7 | : DisplayObject ; // generico var child: DisplayObject / / Generic var i : uint = 0 ; i < this . numChildren ; i ++ ) { for (var i: uint = 0; i <this. numChildren; i + +) { getChildAt ( i ) ; = child containers. getChildAt (s); child is TextField ) { if (child is TextField ) { / / Do something ... } } |
The interesting thing is that if we have exported a library MovieClip class by creating our own CMiaClasse we can write:
1 2 3 4 5 6 7 | : DisplayObject ; // generico var child: DisplayObject / / Generic var i : uint = 0 ; i < this . numChildren ; i ++ ) { for (var i: uint = 0; i <this. numChildren; i + +) { getChildAt ( i ) ; = child containers. getChildAt (s); child is CMiaClasse ) { if (child is CMiaClasse) { / / Do something ... } } |
This character is very useful and allows almost complete control over instances, especially when you have to create the feature to "download" objects that are no longer needed! For example, here is how to "disappear" the hand-drawn Shape:
1 2 3 4 5 | : DisplayObject ; // generico var child: DisplayObject / / Generic var i : uint = 0 ; i < this . numChildren ; i ++ ) { for (var i: uint = 0; i <this. numChildren; i + +) { getChildAt ( i ) ; = child containers. getChildAt (s); child is Shape ) this . removeChild ( child ) ; if (child is Shape ) this. removeChild (child); } |
Amazing! ![]()










There are no comments for this post
Leave a comment