One simple way to create an object instance doesn't involve ActionScript at all. In Flash, when you place a movie clip symbol, button symbol, or text field on the Stage, and you assign it an instance name in the Property inspector, Flash automatically declares a variable with that instance name, creates an object instance, and stores that object in the variable. Likewise, in Adobe Flex Builder when you create a component in Macromedia® MXML™ from Adobe (either by coding an MXML tag or by placing the component on the editor in Design mode) and assign an ID to that component (in the MXML markup or in the Flex Properties view), that ID becomes the name of an ActionScript variable, and an instance of the component is created and stored in the variable.
With several ActionScript data types, you can create an instance using a literal expression, which is a value written directly into the ActionScript code. Here are some examples:
This is Literal numeric value example:
var someNumber:Number = 17.239; var someNegativeInteger:int = -53; var someUint:uint = 22;
This is Literal String value example:
var firstName:String = "George"; var soliloquy:String = "To be or not to be, that is the question...";
This is Literal Boolean value example:
var niceWeather:Boolean = true; var playingOutside:Boolean = false;
This is Literal Array value example:
var seasons:Array = ["spring", "summer", "autumn", "winter"];
This is Literal XML value example:
var employee:XML =
Most common way to create an instance for any data type is to use the new operator with the class name, as shown here:
var raceCar:MovieClip = new MovieClip(); var birthday:Date = new Date(2006, 7, 9);
Creating an object using the new operator is often described as “calling the class’s constructor.” A constructor is a special method that is called as part of the process of creating an instance of a class. Notice that when you create an instance in this way, you put parentheses after the class name. Sometimes you specify parameter values in the parentheses. These are two things that you also do when calling a method.
Details: http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000024.html
No comments:
Post a Comment