浅谈Flex唯一标识UID
UID作为Flex的唯一标识,很多对象中都拥有mx_internal_uid属性,先看看代码:
<?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" minWidth="955" minHeight="600"><s:layout><s:VerticalLayout /></s:layout><fx:Script><![CDATA[import mx.controls.Alert;import mx.utils.ObjectUtil;import mx.utils.UIDUtil;private var _arr:Array = ["a", "b"];private var _obj:Object = {"a": "b"};private function infoA():void{alert(_arr + "", "a,b");}private function infoB():void{_arr.push(_obj);alert(_arr[2], _obj)}private function infoC():void{var u:Number = _arr.length - 1;_arr.pop();alert(_arr.length, u);alert(1, 1.00);}private function infoD():void{var _newArr:Array = _arr;var _oldArr:Array = _arr;_newArr.pop();alert(_newArr, _oldArr);alert(btn.stage, stage);}private function infoE():void{alert(null, undefined);}private function infoF():void{alert(ObjectUtil.clone(_arr), _arr);}private function infoG():void{//alert(ObjectUtil.copy(_arr), _arr);var _newArr:Object = ObjectUtil.copy(_arr);alert(_newArr, _arr);_arr.pop();alert(_newArr, _arr);alert(_newArr.length, _arr.length);}private function alert(oA:Object, oB:Object):void{var _strA:String = UIDUtil.getUID(oA);var _strB:String = UIDUtil.getUID(oB);Alert.show(_strA + "\n" + _strB + "\n" + (_strA == _strB));}]]></fx:Script><s:Button label="方案A" click="infoA()" /><s:Button label="方案B" click="infoB()" /><s:Button label="方案C" click="infoC()" /><s:Button label="方案D" click="infoD()" /><s:Button label="方案E" click="infoE()" /><s:Button label="方案F" click="infoF()" /><s:Button id="btn" label="方案G" click="infoG()" /></s:Application>