Catching SecurityError from flash

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Catching SecurityError from flash

François Rey
When using flash9 URLLoader class, is there a way to catch SecurityError like
in flash, separately from other types of errors?

                try {
                        loader.load( urlRequest );
                } catch ( e : Error ) {
                        // SecurityError?;
                }

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Catching SecurityError from flash

Bruno Garcia
On 04/08/2010 05:49 AM, François Rey wrote:
> When using flash9 URLLoader class, is there a way to catch SecurityError like
> in flash, separately from other types of errors?
>
> try {
> loader.load( urlRequest );
> } catch ( e : Error ) {
> // SecurityError?;
> }
>

catch (e :SecurityError) { } should work.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Catching SecurityError from flash

Robert Sköld
I don't think asynchronous errors (error events) can be caught using a try/catch.

Instead you simply have to add an event listener to it, like this:

        loader.addEventListener( flash.events.SecurityErrorEvent.SECURITY_ERROR , function(e){ // Something } );

Correct me if I'm wrong though :)

/bob

On Apr 8, 2010, at 22:45 , Bruno Garcia wrote:

> On 04/08/2010 05:49 AM, François Rey wrote:
>> When using flash9 URLLoader class, is there a way to catch SecurityError like
>> in flash, separately from other types of errors?
>>
>> try {
>> loader.load( urlRequest );
>> } catch ( e : Error ) {
>> // SecurityError?;
>> }
>>
>
> catch (e :SecurityError) { } should work.
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Catching SecurityError from flash

John A. De Goes

You are right. There are about 20 billion errors (actually 5) that you should listen for or else an uncaught exception will be thrown at some undetermined time in the future when the problem is encountered.

Regards,

John

On Apr 8, 2010, at 2:53 PM, Robert Sköld wrote:

> I don't think asynchronous errors (error events) can be caught using a try/catch.
>
> Instead you simply have to add an event listener to it, like this:
>
> loader.addEventListener( flash.events.SecurityErrorEvent.SECURITY_ERROR , function(e){ // Something } );
>
> Correct me if I'm wrong though :)
>
> /bob
>
> On Apr 8, 2010, at 22:45 , Bruno Garcia wrote:
>
>> On 04/08/2010 05:49 AM, François Rey wrote:
>>> When using flash9 URLLoader class, is there a way to catch SecurityError like
>>> in flash, separately from other types of errors?
>>>
>>> try {
>>> loader.load( urlRequest );
>>> } catch ( e : Error ) {
>>> // SecurityError?;
>>> }
>>>
>>
>> catch (e :SecurityError) { } should work.
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Catching SecurityError from flash

François Rey
On Thursday 08 April 2010 23:04:35 John A. De Goes wrote:
> You are right. There are about 20 billion errors (actually 5) that you
> should listen for or else an uncaught exception will be thrown at some
> undetermined time in the future when the problem is encountered.
>
I'm not sure I understand it right (never done flash before, starting straight
with haXe).
Are you saying that if no listener is registered flash throws a SecurityError?
Also how can a synchonous call to load() throw a SecurityError later on?

My guess would be something like this: URLLoader.load() can throw a
SecurityError in some situation such as accessing a local file. Don't know if
an event is fired as well, I wouldn't think so. At some point, before or when
the request goes on the network, the URLLoader.load() function returns
normally, and any subsequent problem will be signaled via events. No throwing
of anything since the synchronous call to load() has gone.

Example at http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/ shows
both listening and catching.

For now I'm listening and catching, and look for the string "ecurity" in the
error message. A real hack yes, but what else can I do?
Here's the code:

public function load( url :String ) :Void {
        loader = new URLLoader();
        addListeners( loader );
        urlRequest.url = url;
        try {
                loader.load( urlRequest );
        } catch ( e : Error ) {
                if (e.message.indexOf("ecurity") > 0)
                        assetProxy.loadingSecurityError( "Error, id:" + e.errorID + ",
msg:" + e.message );
                else
                        assetProxy.loadingIOError( "Error, id:" + e.errorID + ", msg:"
+ e.message );
        }
}

function addListeners( dis :IEventDispatcher ) :Void {
        dis.addEventListener( ProgressEvent.PROGRESS, progressHandler );
        dis.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler );
        dis.addEventListener( Event.COMPLETE, completeHandler );
        dis.addEventListener( SecurityErrorEvent.SECURITY_ERROR,
securityErrorHandler );
}

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Catching SecurityError from flash

John A. De Goes

On asynch events, Flash looks for a listener to handle the specified error; if it doesn't find one, an exception will be thrown (you'll see it in the Flash debug player).


On Apr 8, 2010, at 4:24 PM, François Rey wrote:

> On Thursday 08 April 2010 23:04:35 John A. De Goes wrote:
>> You are right. There are about 20 billion errors (actually 5) that you
>> should listen for or else an uncaught exception will be thrown at some
>> undetermined time in the future when the problem is encountered.
>>
> I'm not sure I understand it right (never done flash before, starting straight
> with haXe).
> Are you saying that if no listener is registered flash throws a SecurityError?
> Also how can a synchonous call to load() throw a SecurityError later on?
>
> My guess would be something like this: URLLoader.load() can throw a
> SecurityError in some situation such as accessing a local file. Don't know if
> an event is fired as well, I wouldn't think so. At some point, before or when
> the request goes on the network, the URLLoader.load() function returns
> normally, and any subsequent problem will be signaled via events. No throwing
> of anything since the synchronous call to load() has gone.
>
> Example at http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/ shows
> both listening and catching.
>
> For now I'm listening and catching, and look for the string "ecurity" in the
> error message. A real hack yes, but what else can I do?
> Here's the code:
>
> public function load( url :String ) :Void {
> loader = new URLLoader();
> addListeners( loader );
> urlRequest.url = url;
> try {
> loader.load( urlRequest );
> } catch ( e : Error ) {
> if (e.message.indexOf("ecurity") > 0)
> assetProxy.loadingSecurityError( "Error, id:" + e.errorID + ",
> msg:" + e.message );
> else
> assetProxy.loadingIOError( "Error, id:" + e.errorID + ", msg:"
> + e.message );
> }
> }
>
> function addListeners( dis :IEventDispatcher ) :Void {
> dis.addEventListener( ProgressEvent.PROGRESS, progressHandler );
> dis.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler );
> dis.addEventListener( Event.COMPLETE, completeHandler );
> dis.addEventListener( SecurityErrorEvent.SECURITY_ERROR,
> securityErrorHandler );
> }


--
haXe - an open source web programming language
http://haxe.org