In this article we will tell you about basic connection between flash and XML. It will show you what to add in the flash file in order to be able to read tags from an XML file and then use that data inside flash.
Follow below mentioned steps
Step1: Make XML file
The XML file you will make look like this, you will create file called sample.xml and paste this code in that.
In the above XML file the "items" are called XML tags and "item_name" and "price" are called attributes.
"Items" is the first child of the XML file and the lines inside are child 0,1,2 of the first child.
To get the value "IPhone" you have to write this in ActionScript:
To get the value "HTC" use this code in ActionScript:
Step2: Make flash file
Now you have to need create 6 text fields where data item names and item price will be written but this is not important that which format will be use to display this data, in this article we just only trying to explain that how to read the XML data in flash
Now the contents in the flash file…. open Macromedia Flash, create a blank file, click on first key frame, open Actions panel and paste this code:
As you may see, the above code loads data from an external XML file called "sample.xml" and places the data from the XML tags to text fields inside the flash file.
For example: to access the product name on first line ("IPhone") the ActionScript line inside the flash file will be like this:
"xmlData" is the name given to the new XML object at beginning of ActionScript code; the next code are the levels, it reads from first level ("firstChild") this is "products" tag, from "products" tags it loads first child ("childNodes") and the attribute name is "item_name".
So the above line will return the value "IPhone".
As you can see counting starts from zero when counting XML lines.
Item_name, price and XML tags are defined by user, in an XML file you can name the tags and the attributes as you wish, the tags are not predefined like in HTML language.