培训时,讲的ActionScript数据类型。
1.treeData.xml
<?xml version="1.0" encoding="utf-8"?> <rootNode text="家庭理财系统" isActive="false"> <firstNode text="日常管理" isActive="false"> <secondNode id="dayIncome" text="日常收入" isActive="true"></secondNode> <secondNode id="dayOutlay" text="日常支出" isActive="true"></secondNode> <secondNode id="borrowClause" text="借入款项" isActive="true"></secondNode> <secondNode id="loanClause" text="借出款项" isActive="true"></secondNode> </firstNode> <firstNode text="理财报表" isActive="false"> <secondNode id="inOutDetail" text="收支明细" isActive="true"></secondNode> <secondNode id="inOutCollect" text="收支汇总" isActive="true"></secondNode> </firstNode> <firstNode text="系统设置" isActive="false"> <secondNode id="projMan" text="项目管理" isActive="true"></secondNode> <secondNode id="userMan" text="成员管理" isActive="true"></secondNode> </firstNode> </rootNode>
2.DynamicClass.as
package classes { public dynamic class DynamicClass { private var _name:String = null; public function DynamicClass() {} public function get name():String { return _name; } public function set name(value:String):void { _name = value; } } }
3.DataType.mxml
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="creationCompleteHandler(event)" minWidth="955" minHeight="600"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> <fx:XML id="xmldata" source="assets/treeData.xml" format="e4x" /> </fx:Declarations> <fx:Script> <![CDATA[ import classes.DynamicClass; import mx.collections.ArrayCollection; import mx.events.FlexEvent; [Bindable] private var arrayCollection:ArrayCollection = new ArrayCollection([{name:'horay', value:'25'}, {name:'horay1', value:'26'}]); // Flex 数据类型 protected function creationCompleteHandler(event:FlexEvent):void { //---------------------------------------------------- // 基元数据类型 // 包括Boolean、int、Null、Number、String、uint、void // Boolean数据类型 var boolean:Boolean = false; trace("boolean === " + boolean); // int数据类型 var integer:int = 100; var negative:int = -100; trace("integer === " + integer); trace("negative === " + negative); // Null数据类型 var _null:String = null; trace("null === " + _null); // Number数据类型(可以表示整数、无符号整数和浮点数) var number:Number = 1.11; trace("number === " + number); // String数据类型 var string:String = "String......"; trace("string === " + string); // uint数据类型(无符号整型) var _uint:uint = 123456; trace("uint === " + _uint); // void数据类型(见方法体) //---------------------------------------------------- // 复杂数据类型:Object、Array、Date、Error、Function、RegExp、XML、XMLList // Object类型 var object:Object = new Object(); object.string = "string"; object.integer = 100; object.boolean = true; trace("string === " + object.string + ", " + "integer === " + object.integer + ", " + "boolean === " + object.boolean); // Array类型 var arrays:Array = new Array("String", 123456, true, object); for (var i:int=0; i<arrays.length; i++) { trace("arrays[" + i + "]" + arrays[i]); } // Date类型 var date:Date = new Date(); trace("date === " + date.getFullYear() + "-" + (date.getMonth() > 9 ? date.getMonth() : "0" + date.getMonth()) + "-" + (date.getDate() > 9 ? date.getDate() : "0" + date.getDate()) + " " + date.getHours() + ":" + date.minutes + ":" + date.getSeconds()); // Error类型 var error:Error = new Error("error......", 123456); trace("error.message === " + error.message); // Function类型 trace("Function === " + this._function("abcdefghijklmnopqrstuvwxyz")); // RegExp类型 var _regex:RegExp = /^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|[1-9]\d*$/; trace("_regex 1.11 === " + _regex.test("1.11")); trace("_regex abcd === " + _regex.test("abcd")); // XML类型 var xml:XML = xmldata; // XMLList类型 var xmlList:XMLList = xml.child("firstNode");; for each (var _xml:XML in xmlList) { trace(_xml.@text); trace(_xml.@isActive); } // ArrayCollection类型 for each (var object:Object in arrayCollection) { trace(object.name + " " + object.value); arrayCollection.getItemAt(0); } // 运算符 as、is、@ this.u_sign("abcdefghijklmnopqrstvuwxyz"); this.u_sign(xmlList); // 关键字 dynamic、setter、getter var dynamicClass:DynamicClass = new DynamicClass(); dynamicClass.name = "explor"; trace("dynamicClass.name === " + dynamicClass.name); dynamicClass.age = 21; trace("dynamicClass.age === " + dynamicClass.age); } // Function private function _function(string:String):String { return string; } //---------------------------------------------------- // 运算符 as、is、@ private function u_sign(object:Object):void { if (object is String) { var string:String = object as String; trace("String === " + string); } else if (object is XMLList) { var xmlList:XMLList = object as XMLList; for each (var _xml:XML in xmlList) { trace("XMLList === " + _xml.@text); trace("XMLList === " + _xml.@isActive); } } } //---------------------------------------------------- // 关键字 dynamic、internal、const // 定义常量 private const MIN_AGE:int = 21; // internal(指定类、变量、常数或函数可供同一个包中的任何调用程序使用。默认情况下,类、属性和方法属于 internal 命名空间) internal const MAX_AGE:int = 100; ]]> </fx:Script> </s:Application>