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!) 🙂