0

I had this issue for about 4 hours today where I could not load an XML file in AS3. Kept giving me a Stream error. Seems like it couldn't find the file path. So I grabbed the error:

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///C|/Users/Hmmm/Desktop/Flash%20Projects/Jumper/bin/testxml.xml
at com::LoadXML()[C:\Users\Hmmm\Desktop\Flash Projects\Jumper\src\com\LoadXML.as:14]
at com::MainState()[C:\Users\Hmmm\Desktop\Flash Projects\Jumper\src\com\MainState.as:20]

Then I noticed - Jumper/bin/testxml.xml - it's looking for it in the bin folder... Why?? So I moved the file over to bin and voila - it works. Problem is - I don't want it in the bin folder.

Here's My basic XML loader class:

package com
{
import flash.net.URLLoader;  
import flash.net.URLRequest;  
import flash.events.Event;  
import flash.events.EventDispatcher; 

public class LoadXML extends EventDispatcher  
{
    private var dataXML:XML;

    public function LoadXML(xmlFileName:String):void  
    {  
        var xmlLoader:URLLoader = new URLLoader(new URLRequest(xmlFileName));
        xmlLoader.addEventListener(Event.COMPLETE, loadedCompleteHandler);  
    }  

    private function loadedCompleteHandler(e:Event):void  
    {  
         e.target.removeEventListener(Event.COMPLETE, loadedCompleteHandler);  
         try {  
            dataXML = new XML(e.target.data);
        } catch(e:Error) {  
            throw new Error("Error loading XML");  
        }  
    }  
}
}

And my call to it from another class (same folder):

public var xmlloader:LoadXML = new LoadXML("testxml.xml");

Can someone please clarify how to reference this file.... I eventually want multiple xml files to store things like item details, enemy locations, etc for a game. An example path that I would like would be: src/com/maps/mapData.xml ---- Any help is appreciated. Thank you.

PHaZerous
  • 59
  • 9
  • Reading this helped a little. http://stackoverflow.com/questions/13298843/cant-get-my-relative-paths-to-work-with-flashdevelop-and-flex public var xmlloader:LoadXML = new LoadXML("../src/com/testxml.xml"); – PHaZerous Nov 09 '16 at 03:36
  • Why don't you want this file in the bin folder? Where would you prefer to store it instead? – Brian Nov 10 '16 at 16:07

1 Answers1

0

You can load XML from an arbitrary location by specifying the full path:

new LoadXML("C:/Users/Hmmm/Desktop/Flash Projects/Jumper/src/com/testxml.xml");

or by specifying parent directory in a relative path:

new LoadXML("../src/com/testxml.xml");

Do note that it's uncommon to put assets in a ~/src/ folder when you deploy a project to production.

Brian
  • 3,850
  • 3
  • 21
  • 37