Handling a "SecurityError: Error #2148" within Code?
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
