View comments | RSS feed

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>
 ____________


Version 8

Comments


maciekw said on Sep 17, 2005 at 8:09 AM :
whole this thing is very strange construction.
There is no need to create another XML object in onLoad (if readXML is on timeline). So code above, can look like this.

var readXML = new XML();
readXML.load("idMapTest.xml");
readXML.onLoad = function(success) {

for (var x in this.idMap){
trace('idMap.' + x + " = " + newline + this.idMap[x]);
trace('____________' + newline);
}
}

When we look into intrinsic XML declaration, then we can see, that there is no idMap property declaration. So:
1. open (on my PC)
C:\Program Files\Macromedia\Flash 8\en\First Run\Classes\FP8]XML.as
2. add one line:
var idMap:Object;
3. restart Flash

Everything works just fine, and there is no need for additional xml creaction and parsing.
krzepa said on Nov 19, 2005 at 1:07 AM :
I must admit that example mentioned above is rather odd.

One thing I don't understand is throwing error by compiler when you use strong typing. The cause is idMap property.
jayclue said on Mar 5, 2006 at 8:10 AM :
When idMap is used within a class context there is an error thrown out:

There is no property with the name 'idMap'.
for (var xx in readXML.idMap) {
even all variables have been properly declared. Also in the above example by MM there is no datatyping for the XML object and that is the reason why it works.
var readXML = new XML();

This line will also throw an error:
myXML.parseXML(readXML);
because readXML is an XML object but has to be a string.
myXML.parseXML(readXML.toString());//will not give an error
Could you please correct this in particular that there is no property with idMap.

Otherwise it cannot be used.

 

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

Current page: http://livedocs.adobe.com/flash/8/main/00002870.html