2009/02/26

private VS. private static in Class

Main Class:(document )
package{
import flash.display.Sprite;
import flash.events.MouseEvent;
import fl.controls.Button;
public class Main extends Sprite{
public var obj1:Obj;
public var obj2:Obj;
public function Main(){
obj1=new Obj();
obj2=new Obj();
var button:Button=new Button();
button.label='click';
addChild(button);
button.addEventListener(MouseEvent.CLICK,onButtonClick);
}
private function onButtonClick(evt:MouseEvent):void{
obj1.name='obj_1';
trace(obj1.name);
obj2.name='obj_2';
trace(obj2.name);
trace(obj1.name);
}
}
}
Obj Class:
package {
public class Obj {
private var nameObj:String;
public function Obj() {
}
public function set name(nameObj:String):void{
this.nameObj=nameObj;
}
public function get name():String{
return nameObj;
}
}
}
//export the flash then click the button will result=======================//
obj_1
obj_2
obj_1
//==============================================================//

if Obj class modifies as follows and others are the same:

Obj Class:
package {
public class Obj {
private static var nameObj:String;
public function Obj() {
}
public function set name(nameOb:String):void{
nameObj=nameOb;
}
public function get name():String{
return nameObj;
}
}
}
//export the flash then click the button will result=======================//
obj_1
obj_2
obj_2
//==============================================================//
Summary:
I ever cofused the access control attribute when  add private static differentiate only private  in class. private variable in class alreay can't use except inside the class and why add static to use( to access by using class property)??

you see elarly codes  show add static with private:
1. private static variable will be one variable in class when using multi-objects
2. attention when use the  this keyword & arguement name confict when add static status.



2008/10/27

how to pass variables from loading swf to loaded swf?

parent/loading swf:
package{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
public class LoadingSWF extends Sprite{
private var loader:Loader = new Loader();

public function LoadingSWF (){
loader.contentLoaderInfo.addEventListener( Event.INIT, onLoaderInit );
loader.load( new URLRequest( "ExampleB.swf" ) );
}

private function onLoaderInit( event:Event ):void
{
Object( loader.content ).init( "passing" );
}
}
}
/*=======================================*/
child/loaded swf:
package{
import flash.display.Sprite;
public class LoadedSWF extends Sprite{
public function LoadedSWF (){
}
public function init( value:String):void{
trace(value);
}
}
}

2008/10/05

How to See Your AS Code in Flex

Anatomy MXML tag:
//================================================================//
example codes:< id="'btn'" label="Click Me" cornerradius="20" onclick="'....'">
//================================================================//
Tags are Classes: 
import mx.controls.Button; btn:Button=new Button(); addChild(btn);
Attributes are properties:
btn.label='Click Me';
Attributes are styles:
btn.setStyle("cornerRadius", 14);
Attributes are Event Listeners
btn.addEventListener('onclick',someFunction);
//================================================================//

MXML is great for laying out structure, and ActionScript is built for interactivity. In this sample, you see that MXML markup is actually turned into ActionScript by the Flex compiler. Like ColdFusion Meta-Language(CFML) is html-based language transfer java background.

your MXML tag could transfer *.as files in your Flex project by following steps.

First, you open dialog by project>properties.
Second, choose additional compiler arguments under Flex Compiler. then add -keep or  -keep-generated-actionscript parameter at compiler parameters (spearte parameter by space). save the setting.
you could see all *.as used in your project right now in your src/generated folder in Flex Navigator panel.


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