gavin sim logo
 

Week 1

Week 2

Week 3

Week 4

Week 5

Week 6

Week 7

Week 8

Week 9

Teaching > ActionScript

XML Intro

Part 1

Open notepad and type the following:

<?xml version="1.0" encoding="UTF-8"?>
<Publisher>
<Book id="001"> 
<Title> Learn Flash</Title>
<Author>Bob Preston</Author>
</Book>
<Book id="002"> 
<Title> ActionScript for all</Title>
<Author>Ted Smith</Author>
</Book>
</Publisher>

XML is similar to HTML in structure to you need opening and closing tags.There must be a root element in this instance it is publisher, this is referred to as the root node. The other tags e.g. Title is a child of the Book node. You also have whitespace for example a blank line would be classed as a child.

The Book conatins 2 XMLList instances one for the Book attributes (id) and the other for the children (title, author).

save the file as book.xml

 

Exercise

Modify the code to add another child node but this time add a description (giving a description of the book, do this for each book) and then extend the xml document so that it has 3 books.

 

Part 2

Create a new flash doument. Open the actions panel and type:

var book_xml:XML;

This will create a new XML document. Now using the previous tutorials create a URLRequest to load in the XML file. Within the function you will need to add the following code to view the XML data.

 book_xml=new XML(xmlLoader.data);
 trace(book_xml);
 

Note if you have not called the URLLoader xmlLoader then you will need to change this to match.