Flash Connectivity with XML

Flash Connectivity with XML

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.

Hello there! Be the first one to know what's new at Designsmag by subscribing to our RSS feed, or follow us on Twitter, or Join us on Facebook. Promote your post for Free with W3Promoter.
Name: Email:

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.

  1. <?xml version=”1.0″ encoding= “UTF-8″ ?>
  2. <items>
  3.   <item item_name=”IPhone” price=”25.00″></product>
  4.   <item item_name=”HTC” price=”10.00″></product>
  5.   <item item_name=”Nokia” price=”50.00″></product>
  6. </items>

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:
xmlData.firstChild.childNodes[0].attributes.item_name

To get the value “HTC” use this code in ActionScript:

xmlData.firstChild.childNodes[1].attributes.item_name

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:

// define an XML object called “xmlData”
xmlData = new XML();
// load data from an external XML file into “xmlData” object
xmlData.load(“sample.xml”);
// what to do when data is loaded … Call a function (“my_function” in this case)
xmlData.onLoad = my_function;
// ignore “white spaces”, text nodes that only contain white space are discarded
xmlData.ignoreWhite = 1;

// function contents
function my_function() {
// take the data from the XML lines (line 0,1,2) and place that data inside text fields
text_field_1.text = xmlData.firstChild.childNodes[0].attributes.item_name;
text_field_2.text = xmlData.firstChild.childNodes[1].attributes.item_name;
text_field_3.text = xmlData.firstChild.childNodes[2].attributes.item_name;
//
  text_field_a.text = xmlData.firstChild.childNodes[0].attributes.price;
  text_field_b.text = xmlData.firstChild.childNodes[1].attributes.price;
  text_field_c.text = xmlData.firstChild.childNodes[2].attributes.price;
}

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.firstChild.childNodes[0].attributes.item_name

“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[0]“) 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.

 Flash Connectivity with XML
naaz
View all posts by naaz
Husnains website

Recommended Links


Tags: , , , , , , ,

Author : naaz

Author's Website | Articles from

Like this post? Share it!


Related Posts


User Comments


  1. pc games 10
    September 30, 2010

    Hello, this is a really fascinating web blog and ive loved reading several of the articles and posts contained upon the site, sustain the great work and hope to read a lot more exciting articles in the time to come.

    Reply


  2. adurodeek
    October 4, 2010

    it’s such a great site. fabulous, extraordinarily interesting!!!

    ——-

    Reply


  3. I start visiting your site and i have to say that is made with knowledge. I like it.

    Reply


  4. Issac Conch
    October 20, 2010

    Hi! I found your blog on Bing.It’s really comprehensive and it helped me a lot.

    Continue the good work!

    Reply


  5. TOEFL ibt
    October 21, 2010

    Been following your blog posts for few days. Only want to leave a comment say I really love your blog. Cheers!

    Reply


  6. deal of the day
    October 21, 2010

    great post! thanks!

    Reply


  7. Bob Molding
    November 3, 2011

    Terrific Weblog. I add this Weblog to my bookmarks.

    Reply

Rss Feeds   Twitter Followers Email Updates


Community Feeds

  • 25 Awesome Catalog Design

    Catalog design in printed form is very important role play in branding as well as grooming in corporate image building. Without catalog design company's marketing toolkit always incomplete and your products don't generate revenue as per your expectations.

  • 15 Fresh Catalog Design Ideas

    Catalog design is more than just making a collection of creative, colorful pages for flipping through it to get an overall idea of the product or service. To stand out, some designers give that extra touch to the design. Catalogs helps to create a buzz that force users to buy the product even if they don’t really need that product.

  • Landing Pages Guide 101: Create Landing Pages that Work

    In this article you will be taken through each important step in order to create a successful, landing page that converts visitors into customers, I will share the biggest takeaways here and point you to the right articles and tools – let’s call it Landing Pages 101, Science Of Landing Pages, Anatomy of Converting Landing page, whichever you prefer most.

  • 15 Remarkable Social Media Monitoring Tools

    Get the daily traffic details of your social media accounts with the help of 15 Remarkable Social Media Monitoring Tools

  • Typography Posters: 30 Creative Poster Designs

    30 Creative typography poster designs are created by some hard-working and dedicated designers. Typography posters is now more popular and we can notice a surge for fonts type work on portfolio sites, Typography is the design of glyph which is the looks of characters. Designers of typefaces are called type designers, and often

Submit More
Get Adobe Flash player