//------------------------------------------------------------------------------------------------ //xml转义IE安全显示 import mx.utils.XMLString; // ["<"] = "<"; // [">"] = ">"; // ["'"] = "'"; // ["\""]= """; // ["&"] = "&"; // escape,unescape var str = "'samstudio\"&"; trace("escape:\n"+XMLString.escape(str)); trace("unescape:\n"+XMLString.unescape(XMLString.escape(str))); //------------------------------------------------------------------------------------------------ //使用XML 和 HTTP 方式与服务器交换数据解析 //Description: A set of data components that use XML and HTTP for transferring data between a Flash MX client and a server. //The parser class provides the functionality to extract strings, integers, floats, and symbols from a string. import mx.utils.StringTokenParser; // create an array so we can trace what kind of token was found var KINDS:Array = new Array("tkSymbol", "tkString", "tkInteger", "tkFloat"); var t:String = "Here_123Text _ is some text@/ 1234.5e+6 1566 \"my string\" 'another string'"; var q:StringTokenParser = new StringTokenParser(t); var tk:Number = q.nextToken(); while (tk != StringTokenParser.tkEOF) { trace(KINDS[tk]+"="+q.token); tk = q.nextToken(); } //------------------------------------------------------------------------------------------------ //字符串格式化 //The formatting class provides a mechanism for displaying and saving data in the specified format. The constructor accepts the format and an array of tokens and uses these values to create the data structures to support the formatting during data retrieval and saving. var dataFormatter:mx.utils.StringFormatter; dataFormatter = new mx.utils.StringFormatter( "MM/DD/YYYY", "M,D,Y,H,N,S", mx.data.binding.DateBase.extractTokenDate, mx.data.binding.DateBase.infuseTokenDate ); var today:Date = new Date(); trace(dataFormatter.formatValue(today)); // 09/18/2003 //------------------------------------------------------------------------------------------------ //以下层级的object可以完全复制;如果层级再往下加深,加深部分就只是复制地址 //copyProperties 方法会覆盖目标object的相同标签,不同的标签会保留 /* public static function copy( refObj:Object ):Object public static function copyProperties( dstObj:Object, srcObj:Object ):Void */ import mx.utils.ObjectCopy; var oa = {name:"abc", digi:[2, 3, 4], char:{a:"aaa", b:"bbb", c:"ccc"}}; var ob = {name:"cba", digi:[null, null, null, 5], info:{tip:"drink"}}; var oac = ObjectCopy.copy(oa); ObjectCopy.copyProperties(ob, oa); var oe = [55,66,[71,72]] var of = [null,null,null,99] var oec = ObjectCopy.copy(oe); ObjectCopy.copyProperties(of, oe); //------------------------------------------------------------------------------------------------ // 代理方式 /* static function create(obj:Object, func:Function):Function function Delegate(f:Function) function createDelegate(obj:Object):Function */ import mx.utils.Delegate; class BasicSlider extends MovieClip { private var __thumb:MovieClip; public function BasicSlider(Void){ __thumb.onPress = Delegate.create(this, doDrag); } private function doDrag(Void):Void{ } } //------------------------------------------------------------------------------------------------ // 数组的扩展操作 import mx.utils.CollectionImpl /* Collection function addItem(item:Object):Boolean; function clear():Void; function contains(item:Object):Boolean; function isEmpty():Boolean; function getIterator():Iterator; function getLength():Number; function getItemAt( index:Number ):Object; function removeItem(item:Object):Boolean; */ /* Iterator function hasNext():Boolean; function next():Object; */ var ci = new CollectionImpl() ci.addItem("tom");ci.addItem("jim");ci.addItem("sam") trace(ci.contains(4)); // true trace(ci.getLength()); // 3 trace(ci.getItemAt(2)); // sam trace(ci.removeItem("jim")); // true trace(ci.isEmpty()); // false var cii = ci.getIterator() trace(cii.hasNext()); // true trace(cii.next()); // tom ci.clear() trace(ci.isEmpty()); // true //------------------------------------------------------------------------------------------------ // _global.classname 是否存在 import mx.utils.ClassFinder; trace(ClassFinder.findClass("mx.controls.Alert")); trace(ClassFinder.findClass("Alert"));