You are currently browsing the monthly archive for January 2009.

When you pass in parameters to a Flash or Flex application, you can include most special characters without URL encoding the values.

This includes the following characters:
; / ? : @ $ , # - _ . ! ~ * ' ( )

But as I recently discovered, this doesn’t apply to plus (+) signs.

If you pass in a plus sign as part of a parameter, it will automatically be converted into whitespace. To preserve the plus sign, you need to pass in %2b, which is the URL encoding for a plus sign.

To prevent your Flex app from running on certain domains, you’ll need to use JS to check the current domain, and then decide how to disable your application.

Here’s the sample code to retrieve the domain (you’ll notice it takes advantage of the getWindowLocation() method I defined in an earlier post last year):

private function getDomain () : String
{
    var domain : String = getWindowLocation ();

    if (domain != null)
    {
        // removes the “http://” or “https://” prefix
        domain = domain.substring (domain.indexOf (“//”) + 2);

        // removes the “www.” prefix
        if (domain.indexOf (“www.”) == 0)
        {
            domain = domain.substring (4);
        }

        // removes the rest of the URL minus the domain
        if (domain.indexOf (“/”) > 0)
        {
            domain = domain.substring (0, domain.indexOf (“/”));
        }
    }

    return domain;
}


There are several easy ways to disable your application. It all depends on how crafty you want to be about it.

You can check the current domain on preinitialize, for example, and simply never display the UI for a restricted domain (more on that here).

Or you can opt for the classic approach, and open an “undismissable” modal dialog to prevent the user from ever interacting with your application.

(or you can just translate everything into Japanese and invert all the colors… the sky’s the limit!) :-)

I recently discovered something interesting trying to implement a REST API call in an AIR application.

When you load a URL request in Flex, you usually listen for complete, I/O error and security error events on the loader. However, I’ve learned that it’s important to also listen for HTTP response status events when loading a URL request in AIR.

Otherwise you might not receive a response when the result is anything other than success (200). Instead, you’ll receive an I/O error: “Error #2032: Stream Error.”

Consider the following sample code:

var loader : URLLoader = new URLLoader ();

loader.addEventListener (Event.COMPLETE, onComplete);
loader.addEventListener (IOErrorEvent.IO_ERROR, onIOError);
loader.addEventListener (SecurityErrorEvent.SECURITY_ERROR,
    onSecurityError);

// AIR-only!
loader.addEventListener (HTTPStatusEvent.HTTP_RESPONSE_STATUS,
    onHTTPStatus);

loader.load (request);


No action is required in the onHTTPStatus() method above. As long as you are listening for the event, you will always receive a response.

Categories