Skip to main content
Known Participant
June 24, 2015
Question

Handling a "SecurityError: Error #2148" within Code?

  • June 24, 2015
  • 1 reply
  • 4041 views

Hello All,

*Using ​Adobe Flash Professional CS6 and Actionscript 3.0...

Printed Error:

SecurityError: Error #2148: SWF file file:///C|/Documents%20and%20Settings/username/Desktop/myFlashProgram/myProgram.swf cannot access local resource file:///C|/Documents%20and%20Settings/username/Desktop/myFlashProgram/myProgram.cfg. Only local-with-filesystem and trusted local SWF files may access local resources.

    at flash.net::URLStream/load()

    at flash.net::URLLoader/load()

    at myProgram_fla::MainTimeline/frame1()[myProgram_fla.MainTimeline::frame1:149]

Cannot display source code at this location.

Debug session terminated.

In my Actionscript I am creating a URLRequest() var and a URLLoader() var to load a text file from the local filesystem. I was able to get this working perfectly by adding a text file to the directory: "C:\WINDOWS\system32\Macromed\Flash\FlashPlayerTrust\myProgram.txt". Inside the myProgram.txt file is a Path to the folder where the file I want to load with URLLoader() is located.

What I did now was, I commented out the line in the file containing the path to the text file in the FlashPlayerTrust  folder in order to FORCE a security error, which it did do... I did this so I could try and handle this error inside my code, if for some reason the user running my Flash program does not have the FlashPlayerTrust stuff setup for the file.

Is there any sort of EventListener I can add that would get run when this error arises? I tried adding a few different eventlisteners to the URLLoader, but they don't get run when the Error happens... Is the URLLoader the wrong element to assign the EventListeners to?

My URLLoader Code for Loading the "myProgram.cfg" File:

//Create the URLRequest() and URLLoader() Variables:

var localRequest:URLRequest = new URLRequest("myProgram.cfg");

var localLoader:URLLoader = new URLLoader();

    //Set to TEXT Format:

    localLoader.dataFormat = URLLoaderDataFormat.TEXT;

    //Add some EventListeners to the URLLoader() Variable:

    localLoader.addEventListener(Event.COMPLETE, localLoader_complete);

    /*I thought this Listener should capture ALL Error Events, but it did not capture the Security Error #2148, which

     *is why I created the NEXT 2 Listeners...    */

    loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, localLoader_errorHandler);

    //I created these 2 listeners in hopes that one of them would run when this error poped-up:

    localLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, localLoader_securityErrorEvent);

    localLoader.addEventListener(SecurityError, localLoader_securityError);

//Load the File:

localLoader.load(localRequest);

function localLoader_complete(e:Event):void {

    //File loaded successfully, read the file now....

}

function localLoader_errorHandler(e:UncaughtErrorEvent):void {

    // Capture ALL "Unhandled" Errors...

    /* Since at the time I created this, this was the only Error Listener I had for the URLLoader() var so I

     * thought this SHOULD capture that Security Error, but it didn't... */

}

function localLoader_securityErrorEvent(e:SecurityErrorEvent):void {

    //This function did NOT run when Security Error #2148 was triggered...

}

function localLoader_securityError(e:SecurityError):void {

    //Also, this function did NOT run when Security Error #2148 was triggered as well...

}

The reason I want to do this is because, if for ANY reason at all the myProgram.cfg file cannot be read, whether it is an IO Error, Security Error, etc... I want to do something else. But the UncaughtErrorEvent does not seem to catch this security error. What I was hoping to accomplish was to have a single Listener for the loading of the file that would execute in the case of ANY ERROR OCCURING AT ALL (*was trying to do this with the localLoader_errorHandler() function). So I wanted to execute a single function if any sort of error came up when trying to load the myProgram.cfg file, but the UncaughtErrorEvent did not get this Security Error...

Does anyone have any thoughts or suggestions as to how I could handle this? Hopefuly something like this is possible...

Thanks in Advance,

Matt

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
June 25, 2015

you can eliminate all those errors by adjusting your security settings but that's just for testing purposes, Adobe - Flash Player : Settings Manager - Global Security Settings panel

but the main issue is, what kind of app are you creating?  a projector, web-based, air?

mrm5102Author
Known Participant
June 25, 2015

Hey kglad, thanks for the reply!

The idea is that I want to be able to handle/respond to the error if it should be thrown when running on someone else's PC. Right now I can't seem to find a listener that would get executed when this error occurs, or I am assigning the listener to the wrong object...

The program is a flash based program designed using Adobe Flash Pro CS6 and Actionscript 3.0. The program is basically a "Wallboard" that displays data received from an XMLSocket(). The XMLSocket receives data from a C# program running on a remote server within our network, which gets its data from a few different SQL Databases.

I believe I was able to catch the Sandbox error when it was for the XMLSocket()  using the listener below. So I was hoping to be able to do the same for URLLoader().

var socket = new XMLSocket();

socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

function securityErrorHandler(event:SecurityErrorEvent):void {

    trace("\r\r***** ERROR: SECURITY SANDBOX VIOLATION OCCURRED, POSSIBLE XML POLICY FILE NOT FOUND *****\r\r");

}

I had tried yesterday adding a SecurityErrorEvent Listener to the URLLoader() variable, but it did not seem to execute once the error was thrown.

Thanks Again,

Matt

kglad
Community Expert
Community Expert
June 25, 2015

if you're running on someone else's pc are you creating a projector or air app?