0

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.

  • There are two possibilities: 1. Relative URL issue, your SWF loads everything relative to top HTML frame location, not SWF location. 2. Security issue, local-with-filesystem setup is tricky, the best way is to go there and add the location to always trusted: https://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html – Organis Feb 20 '18 at 08:51
  • 1. The URL shows the correct path. 2. I have tried to set the global security settings to "Always allow". Still no luck. – user3383418 Feb 20 '18 at 15:04
  • Does it work when you debugging that from IDE? A few tips that just **might** be helpful. 1. You are using a function local variable to hold the **URLLoader** instance. It is not impossible it gets garbage collected as nothing references it once the function is done. 2. Don't use closures (unnamed unbound functions you declare inside other functions). It could be really confusing what they can or cannot access, being unbound. – Organis Feb 20 '18 at 15:22
  • You mean when I debug it from within Animate? Yes, then it works. As for 1 + 2, yes I am aware - this is a part of a larger project. I just simplified it to isolate the problem for the code example :) – user3383418 Feb 20 '18 at 15:41
  • Back to the security settings then. Add the location you are working with to the list of trusted locations. "Always Allow" might not work. – Organis Feb 20 '18 at 16:11
  • You are absolutely right! When I added the exact location it worked. – user3383418 Feb 20 '18 at 21:31
  • Will you write an answer? – user3383418 Feb 20 '18 at 21:32

1 Answers1

2

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.

Organis
  • 7,243
  • 2
  • 12
  • 14
  • I intend to distribute the SWF to team members, for them to run locally, and the solution is not ideal, as not everyone is tech savvy. It would would be ideal if the SWF could just be db-clicked. On both PC and Mac. If anyone know how I'd be very keen to hear. – user3383418 Feb 20 '18 at 23:11
  • @user3383418 Do you need HTML page at all? You can publish EXE projector, which, I believe, has less security restrictions. – Organis Feb 21 '18 at 00:32
  • True, I might just resort to that, although I - for simplicity - would prefer it to just run the SWF. I worked like a charm before I started loading external XML. – user3383418 Feb 21 '18 at 12:55
  • @user3383418 It still can if you don't need this XML to be exactly **external**. You can embed XML file (which means you can keep it as a separate file, but it goes into the SWF during compilation) and distribute it as a whole. – Organis Feb 21 '18 at 13:12
  • Good suggestion, but the users need access to the XML. – user3383418 Feb 22 '18 at 12:54
  • @user3383418 Open XML as a file via **FileReference** then? – Organis Feb 22 '18 at 13:04
  • @user3383418 To wrap this conversation. HTML + SWF (as well as standalone EXE projector) **do not make a valid desktop application**. As you see, there are many ways to make your app work, yet each and every on of these ways are workarounds of different levels of inconvenience. Or, you can switch to AIR actually and distribute AIR applications, they are legit desktop applications, they also will work both on Windows and Macs as you wanted. – Organis Feb 22 '18 at 13:39