304 CHAPTER 10 USING FLASH TO DISPLAY (Web hosting servers)
304 CHAPTER 10 USING FLASH TO DISPLAY XML The code starts by removing any existing items from the list. Then it declares a variable that will store the DVD id attribute value. The code loops through the childNodes array using a for loop. You ll notice that the construction is the same as within JavaScript: for (var i:Number=0; i < rootNode.childNodes.length; i++) { As in the previous chapters, the code uses the length property of the childNodes array to determine the end point for the loop. Within the loop, the code determines the id attribute value using this code: dvdID = rootNode.childNodes[i].attributes.id; This code finds the relevant childNodearray element and finds the id property within the attributes collection. Finally, the addItem() method adds the id attribute to the dvd_listList component: dvd_list.addItem(dvdID); The other block of code within the Actions panel responds to the user making a selection from the List component: var dvdListener:Object = new Object(); dvdListener.change = function(evtObj:Object):Void { var nodeIndex:Number = evtObj.target.selectedIndex; selectedDVDNode = rootNode.childNodes[nodeIndex]; title_txt.text = selectedDVDNode.childNodes[0].firstChild.nodeValue; format_txt.text = selectedDVDNode.childNodes[1].firstChild.nodeValue; genre_txt.text = selectedDVDNode.childNodes[2].firstChild.nodeValue; } dvd_list.addEventListener("change", dvdListener); The code defines an event listener object called dvdListener and adds it to the dvd_list component, listening for the change event. When the object detects the event, it determines which item the user selected and stores it within the nodeIndex variable: var nodeIndex:Number = evtObj.target.selectedIndex; It then uses that value to set an XMLNode object to reference the appropriate element in the XML object: selectedDVDNode = rootNode.childNodes[nodeIndex]; Finally, the function sets the text property of each TextInput component to the value from the appropriate element in the XML object. For example, the title comes from the first child node (childNodes[0]) of the
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.