MJTheOne

parseXML-AIRapp

Dec 17th, 2012
4,639
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
  3.                        xmlns:s="library://ns.adobe.com/flex/spark"
  4.                        xmlns:mx="library://ns.adobe.com/flex/mx"
  5.                        width="640" height="420">
  6.     <fx:Script>
  7.         <![CDATA[
  8.             private var file:File;
  9.             private var fileStream:FileStream;
  10.             private var xml:XML;
  11.             private var xmlList:XMLList;
  12.             private var total:int;
  13.            
  14.             protected function load(event:MouseEvent):void
  15.             {
  16.                 file = new File();
  17.                 file.addEventListener(Event.SELECT, file_select);
  18.                 file.browseForOpen("Please select a file...", [new FileFilter("XML", "*.xml")]);
  19.             }
  20.            
  21.             protected function file_select(event:Event):void
  22.             {
  23.                 fileStream = new FileStream();
  24.                 fileStream.open(file, FileMode.READ);
  25.                 xml = new XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
  26.                 xmlList = xml.SubTexture;
  27.                 total = xmlList.length();
  28.                 fileStream.close();
  29.                
  30.                 var strings:Vector.<String> = new Vector.<String>();
  31.                 for (var i:int = 0; i < total; i++) {
  32.                     strings.push("public static var " + xmlList[i].@name.split(".")[0] + ":Rectangle = new Rectangle(" + xmlList[i].@x + " , " + xmlList[i].@y + " , " + xmlList[i].@width + " , " + xmlList[i].@height + ");");
  33.                     ta.appendText(strings[i] + "\n");
  34.                 }
  35.             }
  36.            
  37.            
  38.         ]]>
  39.     </fx:Script>
  40.    
  41.     <fx:Declarations>
  42.         <!-- Place non-visual elements (e.g., services, value objects) here -->
  43.     </fx:Declarations>
  44.     <s:TextArea id="ta" left="10" right="10" top="40" bottom="10"/>
  45.     <s:Button x="10" y="10" label="Load File" click="load(event)"/>
  46. </s:WindowedApplication>
Advertisement