CHAPTER 10 USING FLASH TO DISPLAY XML 303 You can press the F9 shortcut key to see the actions added to this frame in the Actions panel. All of the ActionScript required to run this simple application appears on Frame 1 of this layer. I ll work through the code. The code starts by declaring timeline variables. These are similar to variables with global scope in a JavaScript code block: var rootNode:XMLNode; var selectedDVDNode:XMLNode; The rootNode variable stores a reference to the document element. In the dvd.xml file, that s the
element. The selectedDVDNodevariable stores a reference to the DVD chosen by the user. The next code block loads the XML document and sets the onLoad event handler: var oXML:XML = new XML(); oXML.ignoreWhite = true; oXML.onLoad = processXML; oXML.load(”dvd.xml”); When the dvd.xml document loads into Flash, it calls the processXML function. The function appears at the bottom of the Actions panel: function processXML(success:Boolean):Void{ if (success){ if (this.status == 0) { rootNode = this.firstChild; loadList(); } } } This function starts by testing that the XML document loaded successfully. It then checks the value of the status property to make sure that there are no errors. The remaining lines set the value of the rootNode variable to the first child of the loaded XML object, and call the loadList function: rootNode = this.firstChild; loadList(); Setting the rootNode variable is useful because it allows an application to access content from the XML document, without the XML declaration, from anywhere within the Flash movie. The loadList() function loads the content into the Listcomponent: function loadList():Void { dvd_list.removeAll(); var dvdID:Number; for (var i:Number=0; i < rootNode.childNodes.length; i++) { dvdID = rootNode.childNodes[i].attributes.id; dvd_list.addItem(dvdID); } }
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.
This entry was posted
on Wednesday, November 28th, 2007 at 11:21 am and is filed under Tomcat.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.