Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML in Flash

Status
Not open for further replies.

secretsquirrel

Programmer
Mar 22, 2001
202
GB
I wonder if anyone can help me here. This might be a bit complicated and hard to understand...

Imagine I've got a Flash movie containing a map. On this map I want to be able to track the positions of various items moving around the map (indicated by small icons). I would like to pass the positions of the icons into the movie via XML, so the movie could position the icons according to x position and y position variables.

The XML would be structured like this:

<item1>
<xposition>
<yposition>
</item1>
<item2>
<xposition>
<yposition>
</item2>
etc.

Does anyone know of a way to do this?

Let me know if this is unclear...

Thanks in advance.
 
xml parsing works with flash 5 ou higher, tu load a xml file into an xml object, just do this:
Code:
yourxmlobject= new XML();
yourxmlobject.load(&quot;yourfile.xml&quot;);

next you have to go through the object to retrieve nodes values with someting like this :
Code:
for(i=0;i<yourxmlobject.childNodes.length;i++){
   //here is just a simple asign of the value of the node to an array item.
   item[i]=yourxmlobject.childNodes[i];
}
A more complete documentation is available on flash support site

But the thing is that it would be more simple that you write your xml file like this
Code:
<?xml version=&quot;1.0&quot;?>
<item id=&quot;1&quot; xposition=&quot;10&quot; yposition=&quot;25&quot; />
<item id=&quot;2&quot; xposition=&quot;12&quot; yposition=&quot;105&quot; />

Note that XML should contain the xml definition tag to be well formed

so you access item atributes with a code like this :
Code:
for(i=0;i<yourxmlobject.childNodes.length;i++){
   //here is just a simple asign of the value of the node to an array item.
   itemid=yourxmlobject.childNodes[i].attributes.id;
   item[itemid]._x=yourxmlobject.childNodes[i].attributes.xposition;
   item[itemid]._y=yourxmlobject.childNodes[i].attributes.yposition;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top