-
1. Re: reposition a movieclip on stage with coordinates from an xml
kglad Aug 4, 2012 10:24 AM (in response to 4morrone)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);
}
-
2. Re: reposition a movieclip on stage with coordinates from an xml
4morrone Aug 4, 2012 10:42 AM (in response to kglad)thank for your quick response but still not working. the MC just goes to 0,0
-
3. Re: reposition a movieclip on stage with coordinates from an xml
kglad Aug 4, 2012 10:56 AM (in response to 4morrone)are you assigning an x,y for MC?
p.s. if sample_mc is MC, you need to assign its x,y after loading of the xml and those variables are defined.
-
4. Re: reposition a movieclip on stage with coordinates from an xml
Ned Murphy Aug 4, 2012 10:57 AM (in response to 4morrone)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.
-
5. Re: reposition a movieclip on stage with coordinates from an xml
4morrone Aug 4, 2012 11:19 AM (in response to Ned Murphy)im kinda understanding what you mean about making sure the xml get loaded before assigning values, now i got the nmovieclip just staying in its original place on stage. i dont expect it automattically adjust when i edit the xml, just to adjust at runtime.
-
6. Re: reposition a movieclip on stage with coordinates from an xml
Ned Murphy Aug 4, 2012 12:30 PM (in response to 4morrone)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
-
7. Re: reposition a movieclip on stage with coordinates from an xml
4morrone Aug 4, 2012 2:05 PM (in response to Ned Murphy)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.
-
8. Re: reposition a movieclip on stage with coordinates from an xml
Ned Murphy Aug 4, 2012 3:18 PM (in response to 4morrone)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?
-
9. Re: reposition a movieclip on stage with coordinates from an xml
4morrone Aug 4, 2012 3:52 PM (in response to Ned Murphy)i was getting the errors. i declared as XMLList and it worked beeautifully. Thank You very much i hope you are a great asset to us beginners.
-
10. Re: reposition a movieclip on stage with coordinates from an xml
Ned Murphy Aug 4, 2012 4:03 PM (in response to 4morrone)You can help others to help you by providing the complete error messages that you are getting when you post your questions/responses. It can save alot of time finding the problem.
You should mark kGlad's response as being helpful.
-
11. Re: reposition a movieclip on stage with coordinates from an xml
4morrone Aug 4, 2012 4:18 PM (in response to Ned Murphy)will do, this is my first time actually having a discussion i know i have alot to learn about being part of a community.
-
12. Re: reposition a movieclip on stage with coordinates from an xml
Ned Murphy Aug 4, 2012 5:14 PM (in response to 4morrone)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.
-
13. Re: reposition a movieclip on stage with coordinates from an xml
4morrone Aug 4, 2012 5:14 PM (in response to Ned Murphy)do u mean marking as Correct or Helpful
-
14. Re: reposition a movieclip on stage with coordinates from an xml
Ned Murphy Aug 4, 2012 5:16 PM (in response to 4morrone)Yes, or both for different postings that helped you (only one correct can be awarded).
-
15. Re: reposition a movieclip on stage with coordinates from an xml
4morrone Aug 4, 2012 5:21 PM (in response to Ned Murphy)yes i had just saw that u can only reward one correct but i can award a helpful for evey posting right.
-
16. Re: reposition a movieclip on stage with coordinates from an xml
Ned Murphy Aug 4, 2012 5:52 PM (in response to 4morrone)THere used to be a limit of two helpful, and there may still be, but I think it has slipped a gear for awhile now and might allow more.
-
17. Re: reposition a movieclip on stage with coordinates from an xml
4morrone Aug 4, 2012 5:55 PM (in response to 4morrone)its 4 helpfuls now
-
18. Re: reposition a movieclip on stage with coordinates from an xml
Ned Murphy Aug 5, 2012 4:41 AM (in response to 4morrone)Thanks for testing that... it's good info to know.



