20
Sep
07

Determining a Flex application’s current security sandbox type

The following example shows how you can determine the current security sandbox type for a Flex application by checking the static, read-only Security.sandboxType property. You can also check for specific sandbox types by comparing the sandboxType property to the static constants in the Security class (LOCAL_TRUSTED, LOCAL_WITH_FILE, LOCAL_WITH_NETWORK, and REMOTE).

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/20/determing-a-flex-applications-current-security-sandbox-type/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">

    <mx:Script>
        <![CDATA[
            private function init():void {
                switch (Security.sandboxType) {
                    case Security.LOCAL_TRUSTED:
                        sandboxLabel.text += " (Local trusted)";
                        break;
                    case Security.LOCAL_WITH_FILE:
                        sandboxLabel.text += " (Local with file)";
                        break;
                    case Security.LOCAL_WITH_NETWORK:
                        sandboxLabel.text += " (Local with network)";
                        break;
                    case Security.REMOTE:
                        sandboxLabel.text += " (Remote)";
                        break;
                }
            }
        ]]>
    </mx:Script>

    <mx:Form>
        <mx:FormItem label="Security.sandboxType:" fontSize="16">
            <mx:Label id="sandboxLabel" text="{Security.sandboxType}" />
        </mx:FormItem>
    </mx:Form>

</mx:Application>

View source is enabled in the following example.


2 Responses to “Determining a Flex application's current security sandbox type”


  1. 1 John C. Bland II Sep 21st, 2007 at 12:10 am

    Peter, what would be a use-case for this? The only thing I can think of is automatically switching between a live url or a test url (for local dev’ that is).

    BTW, where’s the RSS or subscribe feature for comments? :-D (not that I can really talk but figured I’d ask)

  2. 2 peterd Sep 21st, 2007 at 6:59 am

    Their isn’t a valid use case for this example specifically. But I’m working on the security feature and the loading rules are different for each of the 4 sandbox types.
    Typically when you build an application you’d know where it is being deployed though.

    RSS for comments? There are two. Look in the footer for the site-wide comments, where it says “powered by WordPress and Redoable 1.2″. The link is http://blog.flexexamples.com/comments/feed/.
    If you want RSS for a specific entry, look below the lone Google ad around the entry comments. There should be an orange RSS icon which says “Feed for this Entry”, or, it looks like you can just append “/feed/” to the end of the URL. So for this specific entry it’d be:
    http://blog.flexexamples.com/2007/09/20/determing-a-flex-applications-current-security-sandbox-type/feed/

    Peter

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




September 2007
M T W T F S S
« Aug   Oct »
 12
3456789
10111213141516
17181920212223
24252627282930

Badge Farm

  • Firefox 2
  • Powered by Redoable 1.2
  • Feeds burnt by Feedburner
  • Feed