Working with Methods: Adding Custom Nodes in XML
Updated: Jan 25, 2008
Views: 1283
Description: In this tutorial we will go through the steps on how to create custom nodes in your XML files and extracting the data for use in Flash with Media List As3.0 Component.
Components Used in this Tutorial: Media List AS3.0
Setting up the XML Document
Before you begin make sure that you have successfully installed the component inspector have been able to load content into the Media List component using XML. Also since we will be using ActionScript make sure that you give your Media List an instance name of myList.
Adding a Custom Node to Your XML Document
A cool feature is that you can add custom fields to your xml document and access these inside of flash. The first step is adding the custom node(s) to your XML document.
Access this Custom Node In Flash
Inside of flash you are now able to access this new node the same way you would the other nodes in the xml - path, title, description, and data. Here's an example of how this accessed:
Building a Text Display to Display Our New Content
For a quick example, we will use a dynamic text field to display our selected item's custom node. Here's a link to the XML we used for this example - custom_content.xml. Where the custom xml node we added was <url>.
Example
Complete Code
Setting up the XML Document
Before you begin make sure that you have successfully installed the component inspector have been able to load content into the Media List component using XML. Also since we will be using ActionScript make sure that you give your Media List an instance name of myList.
Adding a Custom Node to Your XML Document
A cool feature is that you can add custom fields to your xml document and access these inside of flash. The first step is adding the custom node(s) to your XML document.
<content>
<item>
<title>Text</title>
<description>Description text</description>
<path>pic.jpg</path>
<data>name.flv</data>
<newnodename>My New Node's Content</newnodename>
</item>
</content>
<item>
<title>Text</title>
<description>Description text</description>
<path>pic.jpg</path>
<data>name.flv</data>
<newnodename>My New Node's Content</newnodename>
</item>
</content>
Access this Custom Node In Flash
Inside of flash you are now able to access this new node the same way you would the other nodes in the xml - path, title, description, and data. Here's an example of how this accessed:
trace (myList.getSelectedItem().newnodename);
Building a Text Display to Display Our New Content
For a quick example, we will use a dynamic text field to display our selected item's custom node. Here's a link to the XML we used for this example - custom_content.xml. Where the custom xml node we added was <url>.
Example
Complete Code
import com.afcomponents.events.MediaListEvent;
import fl.video.VideoEvent;
// play first item
function onMediaListXML(event:MediaListEvent) {
txtDescr.text = myList.getItemAt(0).url;
}
myList.addEventListener(MediaListEvent.XML_LOAD_COMPLETE, onMediaListXML);
//Handle Item Click
function onListItemSelected(event:MediaListEvent) {
txtDescr.text = myList.getSelectedItem().url;
}
myList.addEventListener(MediaListEvent.ITEM_SELECTED, onListItemSelected);
import fl.video.VideoEvent;
// play first item
function onMediaListXML(event:MediaListEvent) {
txtDescr.text = myList.getItemAt(0).url;
}
myList.addEventListener(MediaListEvent.XML_LOAD_COMPLETE, onMediaListXML);
//Handle Item Click
function onListItemSelected(event:MediaListEvent) {
txtDescr.text = myList.getSelectedItem().url;
}
myList.addEventListener(MediaListEvent.ITEM_SELECTED, onListItemSelected);