SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New to flash - scoping issue

    Code Actionscript:
    function loadXML()
    {
    	var book_xml:XML;
     
    	var urlLoader:URLLoader=new URLLoader();
    	var urlRequest:URLRequest=new URLRequest("stories.xml");
     
    	urlLoader.addEventListener(Event.COMPLETE, completeLoading);
    	urlLoader.load(urlRequest);
    	var holder = "";
    	function completeLoading(event:Event):void {
    		//when loading of XML completed, the data can
    		//go into the internal variable of type XML
    		book_xml=new XML(urlLoader.data);
    		//display the XML object book_xml as a text
    		//inside text area myxml_ta
    		holder = book_xml.toString();
    		// if i were to do the trace here it would output properly
    	}
    	// tracing here doesnt output the string
    	trace(holder);
    }

    I can understand what's going on here, and why my XML isn't output. But essentially I need to access that XML outside of the callback function and return it. Is this possible? Is there a naughty way of getting around the scoping issue ?

  2. #2
    SitePoint Addict
    Join Date
    Jul 2005
    Location
    USA
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the event listener is being assigned before the function is defined. try making your reference to book_xml in the application class or on the _root.

  3. #3
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That can't be true because if I put trace(book_xml.toString()); in the callback function it outputs fine.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •