Actionscript文档类XML加载模板
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Actionscript文档类XML加载模板相关的知识,希望对你有一定的参考价值。
import mx.utils.Delegate; dynamic class classes.MainController extends MovieClip { private var __xml:XML; public var xmlPath:String = "xml/settings.xml"; private var __tiles:Array = new Array(); /** ----------------------------------------------------------- * Constructor * ----------------------------------------------------------- */ public function MainController(){ trace("Document Class loaded"); }; public static function main(target:MovieClip):Void { target.__proto__ = MainController.prototype; Function(MainController).apply(target, null); }; private function onLoad():Void{ loadSettings(); }; /** ----------------------------------------------------------- * Properties * ----------------------------------------------------------- */ /** ----------------------------------------------------------- * Public Methods * ----------------------------------------------------------- */ /** ----------------------------------------------------------- * Private Methods * ----------------------------------------------------------- */ private function loadSettings():Void{ __xml = new XML(); __xml.ignoreWhite = true; __xml.onLoad = Delegate.create(this, onXMLLoad); __xml.load(xmlPath); }; private function onXMLLoad(success:Boolean):Void{ if (success){ parseXML(); } }; private function parseXML():Void{ __tiles = filterXMLAssocArray("tile", __xml.firstChild.childNodes); }; // Filters specified tags from a supplied XML Node resource by tag name. // Returns a new associative array with the filtered tags' attributes. private function filterXMLAssocArray(filterNodeName:String, xmlNodes:Array):Array{ var tmpArray:Array = new Array(); for (var i:Number = 0; i<xmlNodes.length; i++){ if (xmlNodes[i].nodeName == filterNodeName){ tmpArray[i] = new Array(); tmpArray[i] = xmlNodes[i].attributes; } } return tmpArray; }; private function print_r( obj, indent ) { if (indent == null) indent = ""; var out = ""; for ( item in obj ) { if (typeof( obj[item] ) == "object" ) out += indent+"[" + item + "] => Object "; else out += indent+"[" + item + "] => " + obj[item]+" "; out += print_r( obj[item], indent+" " ); } return out; } }
以上是关于Actionscript文档类XML加载模板的主要内容,如果未能解决你的问题,请参考以下文章