Mark
Mark

Reputation: 1224

Determine if invoked from webserver

What can I call from within Flex/AS3 that will tell me whether the flex-app/web page is being executed within the local file system or rather was served from a webserver (either localhost or some remote server). Hopefully that's clear. If there's something in Javascript that's acceptable, but some AS3 function would of course be preferable.

Upvotes: 0

Views: 49

Answers (2)

Mike Petty
Mike Petty

Reputation: 949

The Application class has a property: url

url:String [read-only]

Language Version: ActionScript 3.0
Product Version: Flex 4
Runtime Versions: Flash Player 10, AIR 1.5

The URL from which this Application's SWF file was loaded.

Implementation
public function get url():String

Upvotes: 0

Jason Sturges
Jason Sturges

Reputation: 15955

You could use ExternalInterface to obtain the current URL of the app, and evaluate the string for the scheme:

file:///
http://
https://

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               creationComplete="creationCompleteHandler(event)">

    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function creationCompleteHandler(event:FlexEvent):void
            {
                trace(String(ExternalInterface.call(" function(){ return document.location.href.toString();}")));
            }
        ]]>
    </fx:Script>

</s:Application>

Upvotes: 1

Related Questions