Runtime typechecking of Flash specific types

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

Runtime typechecking of Flash specific types

Rasmussen, Mikkel Munck
Hi list

I'm currently working on using the GlobalErrorHandler from Haxe
introduced in the Flash 10.1 API.

According to
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash
/events/UncaughtErrorEvent.html#error, it's recommended to check the
datatype of the error like the AS3 code below.

function uncaughtErrorHandler(event:UncaughtErrorEvent):void {
        var message:String;

        if (event.error is Error) {
                message = Error(event.error).message;
        } else if (event.error is ErrorEvent) {
                message = ErrorEvent(event.error).text;
        } else {
                message = event.error.toString();
        }
}

So my Question is how do I express the following AS3 statement in Haxe?:

if (event.error is Error) {
        // do something
}

I guess I should use the Type class, but I somehow fail to see how to
deal with Flash types.

Best regards
Mikkel Munck Rasmussen


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

Re: Runtime typechecking of Flash specific types

Juraj Kirchheim
On Fri, Nov 11, 2011 at 10:07 AM, Rasmussen, Mikkel Munck
<[hidden email]> wrote:

> Hi list
>
> I'm currently working on using the GlobalErrorHandler from Haxe
> introduced in the Flash 10.1 API.
>
> According to
> http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash
> /events/UncaughtErrorEvent.html#error, it's recommended to check the
> datatype of the error like the AS3 code below.
>
> function uncaughtErrorHandler(event:UncaughtErrorEvent):void {
>        var message:String;
>
>        if (event.error is Error) {
>                message = Error(event.error).message;
>        } else if (event.error is ErrorEvent) {
>                message = ErrorEvent(event.error).text;
>        } else {
>                message = event.error.toString();
>        }
> }
>
> So my Question is how do I express the following AS3 statement in Haxe?:
>
> if (event.error is Error) {
>        // do something
> }

I guess that's: if (Std.is(event.error, flash.errors.Error)) doSomething();

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