I have been preparing an eSeminar on the topic of Flash Security. It was then I started reading about the subject of run-time error handling, like how to handle when security does not permit certain actions. Broadly speaking, there are asynchronous run-time error and synchronous run-time error.
Below is an example of handling async security run-time error when loading of external data is not permitted. As you can see the way to deal with this is to use event listener:
var xmlData:URLLoader = new URLLoader();
xmlData.load(new URLRequest(“http://localhost/FlashSecurity/fms_rss.xml“));
xmlData.addEventListener(Event.COMPLETE, doData);
function doData(e:Event):void
{
result_txt.appendText(xmlData.data);
}
// use event listener to handle asynchronous error
xmlData.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doError);
function doError(e:SecurityErrorEvent):void
{
result_txt.appendText(String(e));
}
Below is an example of handling sync security run-time error when cross-scripting is not permitted. As you can see the way to handle this is to use try/catch mechanism:
var swfContent:Loader = new Loader();
stage.addChild(swfContent);
swfContent.x = swfContent.y = 0;
swfContent.load(new URLRequest(“http://localhost/FlashSecurity/b.swf“));
swfContent.contentLoaderInfo.addEventListener(Event.COMPLETE, doContent);
function doContent(e:Event):void
{
// use a try and catch block to handle synchronous error
try
{
swfContent.content["lensFlare_mc"].play();
}
catch (e:Error)
{
result_txt.appendText(String(e));
}
}
You can find more details description of error handling at the AS 3 help.
Posted in Uncategorized