Search code examples
actionscript-3flashadobeadobe-animate

SWF cannot load local XML file in browser


I need a local SWF to load a local XML file when running in a browser. The SWF and XML are placed locally on my HD in the same directory, which - as far as I understand - should be OK? But in a browser the XML does not load - output reads "begin" and I cannot get any of the events to trigger. Whereas when running directly from Animate or in the Flash player it works and the output reads "success".

package  {  
    import flash.display.MovieClip;
    import flash.errors.IOError;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.text.TextField;
    import flash.events.SecurityErrorEvent;
    import flash.events.HTTPStatusEvent;

    public class main extends MovieClip {

        private var output:TextField;

        public function main() {

            output = new TextField();
            output.width = 600;
            output.text = "begin";
            addChild(output);

            var urlLoader:URLLoader = new URLLoader();
            urlLoader.addEventListener(Event.COMPLETE, function(e:Event){
                output.text = "success";
            });
            urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, function(e:Event) {
                output.text = "http status event";
            });
            urlLoader.addEventListener(IOErrorEvent.IO_ERROR, function(e:Event) {
                output.text = "io error";
            });
            urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(e:SecurityErrorEvent) {
                output.text = "security error";
            });
            urlLoader.load(new URLRequest("test.xml"));
        }
    }
}

As suggested in the comments, I have tried to set the "Global Security Settings Panel" to "Always allow" but it does not make a difference.


Solution

  • Local-with-filesystem setup is tricky, the easiest way is to go to Flash Player Global Security Settings and add the folder you are debugging in to the list of always trusted locations. Checking the "Always Allow" option might not work, no idea why, as I said - tricky.