One-liner for checking FREResult

We continue our Translating between ActionScript and Objective-C series with another auxiliary function that turns lengthy Objective-C code into one-liner you can reuse in all of your iOS ANEs.

What was covered so far?

What will this part cover?

Today you will add another auxiliary function to your library of one-liners that make life easier and iOS ANE development – quicker.

The function looks like this:

And does various checks for you: did a C AIR API call succeed, if not, what error code it returned and why.

Why is FREResult interesting?

If you have a peek inside FlashRuntimeExtensions.h, you will notice that most AIR C API functions return FREResult, which looks like this:

If you are new to any of the C language flavors, an enum is a data type, which holds together a set of named values, usually numeric. When an AIR C API function returns FRE_WRONG_TRHEAD, it’s the same as returning the number 7, but a bit more meaningful.

The implementation

Having a function that checks that result for you and does something when there is an error, i.e. anything different from FRE_OK, will save you having to repeat those checks over and over again. The isFREResultOK function defined below checks whether the FREResult we’ve got is an error and if it is, it sends an error event back to ActionScript and reports the error in Xcode’s debug console:

Result

Now you can do quick checks in any part of your code:

Additional information

What’s next?

In the next tutorial you will implement a handler for exceptions from FRE* functions and see why you might want to do that.

Info: For a comprehensive data conversion guide and how to make it into a library download our eBook “iOS vs. ActionScript Data Types Guide”.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">