idMap (XML.idMap property)

public idMap : Object

An object containing the XML file's nodes that have an id attribute assigned. The names of the properties of the object (each containing a node) match the values of the id attributes.

Consider the following XML object:

 <employee id='41'>
 <name>
 John Doe
 </name>
 <address>
 601 Townsend St.
 </address>
 </employee>

 <employee id='42'>
 <name>
 Jane Q. Public
 </name>
 </employee>
 <department id="IT">
 Information Technology
 </department>

In this example, the idMap property for this XML object is an Object with three properties: 41, 42, and IT. Each of these properties is an XMLNode that has the matching id value. For example, the IT property of the idMap object is this node:

 <department id="IT">
 Information Technology
 </department>

You must use the parseXML() method on the XML object for the idMap property to be instantiated.

If there is more than one XMLNode with the same id value, the matching property of the idNode object is that of the last node parsed, as follows:

var x1:XML = new XML("<a id='1'><b id='2' /><c id='1' /></a>");
x2 = new XML();
x2.parseXML(x1);
trace (x2.idMap['1']);

The following will output the <c> node:

 <c id='1' />

Availability: ActionScript 1.0; Flash Player 8

Example

You can create a text file named idMapTest.xml that contains the following text.

 <?xml version="1.0"?> 
 <doc xml:base="http://example.org/today/" xmlns:xlink="http://www.w3.org/1999/xlink"> 
 <head> 
 <title>Virtual Library</title> 
 </head> 
 <body> 
 <paragraph id="linkP1">See <link xlink:type="simple" xlink:href="new.xml">what's 
 new</link>!</paragraph> 
 <paragraph>Check out the hot picks of the day!</paragraph> 
 <olist xml:base="/hotpicks/"> 
 <item> 
 <link id="foo" xlink:type="simple" xlink:href="pick1.xml">Hot Pick #1</link> 
 </item> 
 <item> 
 <link id="bar" xlink:type="simple" xlink:href="pick2.xml">Hot Pick #2</link> 
 </item> 
 <item> 
 <link xlink:type="simple" xlink:href="pick3.xml">Hot Pick #3</link> 
 </item> 
 </olist>
 </body> 
 </doc>

Then you can create a SWF file in the same directory as the XML file. You can include the following script in the SWF.

var readXML = new XML();
readXML.load("idMapTest.xml");
readXML.onLoad = function(success) {
    myXML = new XML();
    myXML.parseXML(readXML); 
    for (var x in myXML.idMap){
        trace('idMap.' + x + " = " + newline + myXML.idMap[x]);
        trace('____________' + newline);
    }
}

When you test the SWF file, the following output is generated.

 idMap.bar = 
 <link id="bar" xlink:type="simple" xlink:href="pick2.xml">Hot Pick #2</link>
 ____________

 idMap.foo = 
 <link id="foo" xlink:type="simple" xlink:href="pick1.xml">Hot Pick #1</link>
 ____________

 idMap.linkP1 = 
 <paragraph id="linkP1">See <link xlink:type="simple" xlink:href="new.xml">what's 

 new</link>!</paragraph>
 ____________


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00002331.html