I have xml file with data like name, discription and Xcor, Ycor. I made each of object display on stage in this place what write in xml X and Ycor I also made for each diffrent name other MC - it's work well But when i try option trace to show name of MC after rollOver on it - it always show name "Karkow" - but is wrong becouse every of this MC had diffrent name in xml file
Do You have any idea why it's always see Krakow against other name?
This is my xml code:
<?xml version="1.0" encoding="utf-8" ?>
- <XML>
- <myXMLList>
- <object>
<name>Warszawa</name>
<opis>jakis opis</opis>
<Xcor>100</Xcor>
<Ycor>50</Ycor>
</object>
- <object>
<name>Wroclaw</name>
<opis>jakis opis2</opis>
<Xcor>20</Xcor>
<Ycor>200</Ycor>
</object>
- <object>
<name>Krakow</name>
<opis>jakis opis3</opis>
<Xcor>50</Xcor>
<Ycor>250</Ycor>
</object>
</myXMLList>
</XML>
And this my as3 code:
import flash.display.MovieClip;
import flash.display.Shape;
import flash.accessibility.Accessibility;
import flash.display.DisplayObject;
import flash.geom.Point;
import flash.events.Event;
import flash.events.MouseEvent;
// Initialize the XML, place the xml file name, initialize the URLRequest
// put URLRequest into a new URLLoader, and add event listener on
// myLoader listening for when the XML loading is complete
var myXML:XML = new XML();
var XML_URL:String = "miasta.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
// Create the xmlLoaded function
function xmlLoaded(event:Event):void {
// Place the xml data into the myXML object
myXML = XML(myLoader.data);
// Initialize and give var name to the new external XMLDocument
var xmlDoc:XMLDocument = new XMLDocument();
// Ignore spacing around nodes
xmlDoc.ignoreWhite = true;
// Define a new name for the loaded XML that is the data in myLoader
var menuXML:XML = XML(myLoader.data);
// Parse the XML data into a readable format
xmlDoc.parseXML(menuXML.toXMLString());
// Run the "for each" loop to iterate through all of the menu items listed in the external XML file
for each (var object:XML in myXML..object) {
// Access the value of the "name" node in our external XML file
var name:String = object.name.toString();
// Access the value of the "opis" node in our external XML file
var opis:String = object.opis.toString();
// zmiana koordynat na string
var Xcor:String = object.Xcor.toString();
var Ycor:String = object.Ycor.toString();
//change coordinate to number
var XcorNum = Number(Xcor);
var YcorNum = Number(Ycor);
if (name == "Warszawa") {
var myMovieClip:MovieClip = new Policja();
}
else if (name == "Wroclaw") {
var myMovieClip:MovieClip = new owal();
}
else if (name == "Krakow") {
var myMovieClip:MovieClip = new city();
}
addChild(myMovieClip);
// Set the location of the new MovieClip
myMovieClip.x = XcorNum;
myMovieClip.y = YcorNum;
myMovieClip.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandler);
myMovieClip.buttonMode = true;
myMovieClip.useHandCursor = true;
function onRollOverHandler(myEvent:MouseEvent){
trace (name);
}