Hello i am new to this forum, and kinda a beginner with actionscript. what i'm trying to do is reposition a movieclip already with the coordinates that will be in an XML file on my server. But so far no luck.
This is what i have for AS3
var my_x:Number;
var my_y:Number;
var myCoord:XML;
sample_mc.x = my_x;
sample_mc.y = my_y;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("coords.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML (e:Event):void{
var myXML:XML = new XML(e.target.data);
myCoord = myXML.position.pos1;
my_x = myCoord.@XPOSITION;
my_y = myCoord.@YPOSITION;
}
And the XML file
< position>
< pos1 XPOSITION="100" YPOSITION="55">
< /pos1>
< /position>
let me know if anyone can correct what i'm doing wrong, please.
use:
var my_x:Number;
var my_y:Number;
var myCoord:XML;
sample_mc.x = my_x;
sample_mc.y = my_y;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("coords.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML (e:Event):void{
var myXML:XML = new XML(e.target.data);
myCoord = myXML.pos1;
my_x = Number(myCoord.@XPOSITION);
my_y = Number(myCoord.@YPOSITION);
}
If sample_mc is the movieclip you want to place, you need to wait until after the xml file is loaded and processed before assigning it to those values. If you change the mc_x/mc_y values, the sample_mc will not automatically adjust with them. It is only set when it is assigned to the values they currently hold.
In your processXML function you would assign the values...
function processXML (e:Event):void{
var myXML:XML = new XML(e.target.data);
myCoord = myXML.pos1;
sample_mc.x = my_x = Number(myCoord.@XPOSITION);
sample_mc.y = my_y = Number(myCoord.@YPOSITION);
}
I only include the mc_x and mc_y in the event you use them for some other purpose
still no prevail, this is now what i got so far
AS3
var my_x:Number;
var my_y:Number;
var myCoord:XML;
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("coords.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML (e:Event):void{
var myXML:XML = new XML(e.target.data);
myCoord = myXML.pos1;
sample_mc.x = my_x = Number(myCoord.@XPOSITION);
sample_mc.y = my_y = Number(myCoord.@YPOSITION);
}
and the XML
< position>
< pos1 XPOSITION="100" YPOSITION="55">< /pos1>
< /position>
i know i'm just a beginner with AS but i really thought this was something simple. do i have obvious errors.
If I run your code as shown and repair the xml to not have spaces in the start of the tags, then I get an error regarding :
TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@267470a1 to XML.
for line the line where you assign myCoord. This tells me that you need to EITHER declare myCoord as an XMLList object instead of an XML object, as in...
var myCoord:XMLList;
OR, in the function you need to force myCoord to be an XML object, as in...
myCoord = new XML(myXML.pos1);
Have you been getting error messages?
Just in case... When I mentioned you should mark kGlad's response as helpful I was not intending you to use the...
Was this helpful? Yes No
that you see in the posting. As the original poster you have have the ability to award points to people that help you. While I am not sure what it looks like, it is not the bit I showed above. There should be other options to mark a posting as correct or helpful.
North America
Europe, Middle East and Africa
Asia Pacific