Run-time Error Handling for Flash App

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.

Advertisements

~ by brianchau on August 8, 2009.

One Response to “Run-time Error Handling for Flash App”

  1. cool! Thx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: