Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9269577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:09:30+00:00 2026-06-18T15:09:30+00:00

im new to AS3. Looking to save data that i’ve loaded from an xml

  • 0

im new to AS3. Looking to save data that i’ve loaded from an xml file into a variable. then call that variable later on.

heres my code:

package {

import flash.display.MovieClip;
import flash.events.*;
import flash.display.Stage;
import flash.text.TextField;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLLoaderDataFormat;
import flash.net.URLVariables;

public class myClass extends MovieClip {
        public static var objectOneTotal:int = 1;
        public static var objectOneCurrent:int = 1;


    public function myClass() {


        var myXML:XML;
        var myLoader:URLLoader = new URLLoader();
        myLoader.load(new URLRequest("beers.xml"));
        myLoader.addEventListener(Event.COMPLETE, processXML);

            function processXML(event:Event):void {
            myXML = new XML(event.target.data);

            myClass.objectOneCurrent = int(myXML.current);
            myClass.objectOneTotal = int(myXML.total);

            trace(myClass.objectOneCurrent);
            trace(myClass.objectOneTotal);

            }

        trace(myClass.objectOneCurrent);
        trace(myClass.objectOneTotal);
        var objectOneStart:int = objectOne.x;
        objectOne.x = (objectOneCurrent / objectOneTotal)  * (finish.x - objectOneStart);

    }

}

}

What its doing: when i run it, looking at the traces, its tracing the objects initial values of “1” before its tracing the values which are loaded from the xml. So i believe it is loading the data, but the program is only running the processXML function after the rest of the code. or something.

Im not really sure. but i need the last two traces to read the xml data.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:09:32+00:00Added an answer on June 18, 2026 at 3:09 pm

    Because AS3 is asyncronous, it will execute the entirety of the MyClass method before the XML is loaded. When the XML does load, the code defined in processXML is executed to handle it.

    The solution to this is to make processXML handle set object1.x:

    package {
    
        import flash.display.MovieClip;
        import flash.events.*;
        import flash.display.Stage;
        import flash.text.TextField;
        import flash.net.URLLoader;
        import flash.net.URLRequest;
        import flash.net.URLRequestMethod;
        import flash.net.URLLoaderDataFormat;
        import flash.net.URLVariables;
    
        public class myClass extends MovieClip {
                public static var objectOneTotal:int = 1;
                public static var objectOneCurrent:int = 1;
    
    
            public function myClass() {
                var myXML:XML;
                var myLoader:URLLoader = new URLLoader();
                myLoader.load(new URLRequest("beers.xml"));
                myLoader.addEventListener(Event.COMPLETE, processXML);
    
                // these will fire before the XML is loaded
                trace(myClass.objectOneCurrent);
                trace(myClass.objectOneTotal);
    
    
            }
    
            public function processXML(event:Event):void {
                myXML = new XML(event.target.data);
    
                myClass.objectOneCurrent = int(myXML.current);
                myClass.objectOneTotal = int(myXML.total);
    
                // these fire after the XML is loaded
                trace(myClass.objectOneCurrent);
                trace(myClass.objectOneTotal);
    
                var objectOneStart:int = objectOne.x;
                objectOne.x = (objectOneCurrent / objectOneTotal)  * (finish.x - objectOneStart);
    
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to AS3 and have been working on an XML driven navigation system
Just going to say that I'm new to AS3, What I'm trying to do
I have this AS3 slideshow code, that loads an XML with a list of
I'm new to Flash/AS3 and I have been trying to display objects from class
I am trying to parse some XML in AS3 that I recieve thru a
I am very new to AS3, and I'm confused about how things that would
I've got an AS3 SWF that I'm going to be loading other SWFs into.
I am new to AS3. For graphical representation I use fla file as a
I am new to AS3. When learning AS3, I get the below code from
I'm new to AS3 and I'm getting this error while trying to implement OO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.