• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

reposition a movieclip on stage with coordinates from an xml

Explorer ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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.

TOPICS
ActionScript

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 04, 2012 Aug 04, 2012

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);

}

Votes

Translate

Translate
Community Expert ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

thank for your quick response but still not working. the MC just goes to 0,0

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

will do, this is my first time actually having a discussion i know i have alot to learn about being part of a community.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

do u mean marking as Correct or Helpful

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

Yes, or both for different postings that helped you (only one correct can be awarded).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

yes i had just saw that u can only reward one correct but i can award a helpful for evey posting right.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2012 Aug 04, 2012

Copy link to clipboard

Copied

its 4 helpfuls now

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 05, 2012 Aug 05, 2012

Copy link to clipboard

Copied

LATEST

Thanks for testing that... it's good info to know.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines