Actionscript文档类XML加载模板

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Actionscript文档类XML加载模板相关的知识,希望对你有一定的参考价值。

  1. import mx.utils.Delegate;
  2. dynamic class classes.MainController extends MovieClip
  3. {
  4. private var __xml:XML;
  5. public var xmlPath:String = "xml/settings.xml";
  6.  
  7. private var __tiles:Array = new Array();
  8.  
  9. /** -----------------------------------------------------------
  10.   * Constructor
  11. * -----------------------------------------------------------
  12. */
  13. public function MainController(){
  14. trace("Document Class loaded");
  15. };
  16.  
  17. public static function main(target:MovieClip):Void {
  18. target.__proto__ = MainController.prototype;
  19. Function(MainController).apply(target, null);
  20. };
  21.  
  22. private function onLoad():Void{
  23.  
  24. loadSettings();
  25. };
  26.  
  27. /** -----------------------------------------------------------
  28. * Properties
  29. * -----------------------------------------------------------
  30. */
  31.  
  32. /** -----------------------------------------------------------
  33. * Public Methods
  34. * -----------------------------------------------------------
  35. */
  36.  
  37.  
  38. /** -----------------------------------------------------------
  39. * Private Methods
  40. * -----------------------------------------------------------
  41. */
  42. private function loadSettings():Void{
  43.  
  44. __xml = new XML();
  45. __xml.ignoreWhite = true;
  46. __xml.onLoad = Delegate.create(this, onXMLLoad);
  47. __xml.load(xmlPath);
  48. };
  49.  
  50. private function onXMLLoad(success:Boolean):Void{
  51. if (success){
  52. parseXML();
  53. }
  54. };
  55.  
  56. private function parseXML():Void{
  57. __tiles = filterXMLAssocArray("tile", __xml.firstChild.childNodes);
  58. };
  59.  
  60.  
  61.  
  62.  
  63. // Filters specified tags from a supplied XML Node resource by tag name.
  64. // Returns a new associative array with the filtered tags' attributes.
  65. private function filterXMLAssocArray(filterNodeName:String, xmlNodes:Array):Array{
  66.  
  67. var tmpArray:Array = new Array();
  68.  
  69. for (var i:Number = 0; i<xmlNodes.length; i++){
  70. if (xmlNodes[i].nodeName == filterNodeName){
  71. tmpArray[i] = new Array();
  72. tmpArray[i] = xmlNodes[i].attributes;
  73. }
  74. }
  75. return tmpArray;
  76. };
  77.  
  78. private function print_r( obj, indent ) {
  79.  
  80. if (indent == null) indent = "";
  81. var out = "";
  82. for ( item in obj ) {
  83. if (typeof( obj[item] ) == "object" )
  84. out += indent+"[" + item + "] => Object ";
  85. else
  86. out += indent+"[" + item + "] => " + obj[item]+" ";
  87. out += print_r( obj[item], indent+" " );
  88. }
  89. return out;
  90. }
  91. }

以上是关于Actionscript文档类XML加载模板的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 PureMVC文档类模板

ActionScript 3 基本文档类模板,由FlashDevelop创建

ActionScript 3 加载xml

ActionScript 3 基本的外部XML加载器

ActionScript 3 加载xml

ActionScript 3 AS3:XML加载