2008/09/07

Astra─Tree component in AS 3.0

i discover component library in Flash CS3 has no tree component.
And i don't know why Adobe doesn't support it now.
so i search the google .....super!! Finally i found yahoo developer center provides useful components in AS3.0.

http://developer.yahoo.com/flash/

yahoo developer center includes a lot of information like Astra Flash Library Documentation to intro how to use them. even you can download all source to your computer including library document. ha... it is not bad.
although, i not yet use it's componen. but i hope it's component support dynamic showing icons in AS3.0.

2008/9/9
I used tree component and try to show dynamic icons by external file.....But it was not work....Maybe my ability isn't good enough. 
I find someone resolve like kind of problem, but his developing environment is in Flex builder.
i also find that tree component still exists in Flex 3. And there are a lot of components to use in Flex.....> <. I think I will learn Flex developing environment  someday.

2008/09/03

How stage, root, and MainTimeline Fit Together

this article is form a flash forum. i think the article is worth to keep it. so i post it here.

When you create a new ActionScript 3 application/movie, you're working with a main timeline as the "root" of your application. This root that *you* as a developer are working with then gets added to the stage when your main timeline instance is instantiated. This instance represents the root that is a property of DisplayObject. It is your main timeline.

In the property inspector in Flash CS3 you can associate a custom class with your root (aka main timeline) by filling out the document class field (available when nothing on the screen is selected). Whatever class you specify there has to be at least a Sprite, however, since a) it needs to exist as a child of stage and b) because other instances exist within this instance (unless code is used to explicitly move them to stage). If you do not specify a class for the document class Flash will create one for you called MainTimeline. This instance represents the root that is a property of DisplayObject. It is your main timeline.

If you write code in a timeline, you are defining code that will become part of the class definition of that movie clip symbol, or in the case of the main timeline, since it isnt a symbol, definitions specific to the MainTimeline or document class definition. If you both specify a class for the document class AND write code in the main timeline, then you will have to be sure that your document class extends at least MovieClip (instead of Sprite) since you are using frames in that movie clip (to write code) and it will not work for Sprite instances.

In all respects to the developer, the main timeline is the root of the application. Fittingly so, it is also the instance referenced by the root property of DisplayObject instances within that SWF. The root instance, however, is not the absolute root of the display list hierarchy. That title belongs to the stage instance.

The stage instance is an instance of the Stage class which is instantiated when the Flash player starts. It represents the stage or top-most level of the Flash player. SWFs are then loaded into this stage container with their root instances and played as a child of stage. DisplayObject instances have a stage property that reference this Stage instance.

The stage, however, unlike root, cannot be modified by Flash developers. It is always an instance of the Stage class and always the top level of the display hierarchy within the Flash player.

When a SWF is played, it will always start with 2 display objects in the display hierarchy, the stage instance with a single child of the root instance (MainTimeline instance or an instance of your document class if specified). Other instances would be generated by contents of the SWF and are typically children of root (though it is possible to add additional children to stage through ActionScript). Any symbols or graphics in the main timeline in Flash are children of root (as, again, root is the main timeline)

ALL DisplayObject instances have root and stage properties. Each of these properties (when valid) for any display object within a single SWF reference same root and stage instances, there are only one of each (the only exception is the root property of the stage which references the stage). These properties are null if you have an instance who is not a child of a display list within the stage display hierarchy.

For loaded SWFs, the stage properties of its DisplayObject instances will reference the same stage as that referenced in the SWF that loaded it; there can be only one stage. For loaded SWFs, however, the root property will reference that loaded SWF's root, or its main timleine instance, not the root of the SWF that did the loading.

To summarize: one stage, one root per SWF (which is the main timeline) and that root is an instance of a document class or the MainTimeline class if a document class isn't provided

2008/09/01

When to use the Event.ADDED_TO_STAGE?

form:http://www.flepstudio.org/forum/tutorials/775-event-added_to_stage.html

Here we are again with a new trick of the day (even though I do not consider it as a trick but pure extract of OOP). This one could help us more then once when developing application with Flash CS3.

I am talking about the event Event.ADDED_TO_STAGE.

We need a good example to arrive to the point of this tutorial.

Let us suppose that we have a MovieClip on stage named 'container_mc' and a second MovieClip named 'quadrato_mc'.

We would like to attach another MovieClip placed in library (associated to a class named 'clip') inside container_mc. Up till there everything is fine as we know more then once how to do it: take a look at this article to refresh your memory if needed.

My question to you at this point, would be:

do we need to create the class associated to the MovieClip that we want to attach o shall we let Flash do the job for us to create it ?

Personally, I do think that we should always create it ourself.

First of all, doing so, we do not need to write codes inside the MovieClip as we would write everything in the class keeping full control and keep away from unwanted errors.

The second point is that we can maintain the whole hierarchical tree of our application.

I explain myself better:

And if we wanted to retrieve quadrato_mc placed on stage from the attached clip that is found inside container_mc'

We know that the famous _root does not exist anymore and up till now we have used the technique to pass the value of the stage from the Document Class implementing the building function, from the class associated to the attached MovieClip, a receiving parameter inserted in a property.

It is not easy to explain it by words so let us see a concrete example'
Up till now, we have used this technique:

- a FLA named 'main.fla' into which we have a MovieClip placed on stage with an instance name 'container_mc' and a second one named 'quadrato_mc'


- a Document Class named 'Main.as'

Code:
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
public function Main() {
} } }


- the class, named Clip.as, associated to the MovieClip, named mc_clip, placed in library

Code:
package {
import flash.display.MovieClip;
public class Clip extends MovieClip {
private var _fla:MovieClip;
public function Clip(fla:MovieClip) {
_fla=fla;
} } }

We attach mc_clip inside container_mc from the Document Class the following way:

Code:
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
public function Main() {
attachClip();
}
private function attachClip():void {
var clip:MovieClip=new Clip(this);
container_mc.addChild(clip);
} } }

and if we wanted to retrieve quadrato_mc placed on stage from Clip.as:

Code:
package {
import flash.display.MovieClip;
public class Clip extends MovieClip {
private var _fla:MovieClip;
public function Clip(fla:MovieClip) {
_fla=fla;
trace(_fla.quadrato_mc);
} } }


Is it possible that from Clip.as there is not a way to retrieve the stage without having to go through the Document Class'!'The answer is using Event.ADDED_TO_STAGE .Let us see how.The same Document Class:


Code:
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
public function Main() {
} } }


Clip.as becomes as following:


Code:
package {
import flash.display.MovieClip;
public class Clip extends MovieClip {
public function Clip() {
} } }

If I instance Clip from Main:

Code:
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
public function Main() {
attachClip();
}

private function attachClip():void {
var clip:MovieClip=new Clip();
container_mc.addChild(clip);
} } }

and in the building function of Clip.as I try to retrieve the parent (which would be container_mc)

Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Clip extends MovieClip {
public function Clip() {
trace(parent);
} } }

I obtain a null!When I instance Clip, the building function is looking for the parent to carry out the trace. It can not find it as it has not been inserted yet into container_mc. In fact, container_mc.addChild(clip); is further down the line after I created the instance of Clip. This is why I needed to pass the value of the stage.Instead, if I add to Clip a listener to the event Event.ADDED_TO_STAGE, everything works out fine:

Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Clip extends MovieClip {
public function Clip() {
addEventListener(Event.ADDED_TO_STAGE,go);
}
private function go(evt:Event):void {
removeEventListener(Event.ADDED_TO_STAGE,go);
var _root:MovieClip=parent.parent as MovieClip;
trace(_root.quadrato_mc);
} } }

See you soon !