*blog... kind of... *rss
Detect if the swf is being executed localy or online
19 comments written so far...Ends up as a very simple line, but took a bit to figure it out.
var localMode : Boolean = loaderInfo.url.indexOf("file") == 0;Helpful. I usually ended up checking to see if my FlashVars were set to null or not. This is a lot mo' betta. Thanks.
April 2nd 2009, hebchop
Ditto.. just tried it against a check on my local dev server
var localMode : Boolean = loaderInfo.url.indexOf("http://localhost") == 0;
var localMode : Boolean = loaderInfo.url.indexOf("http://localhost") == 0;
I used to use that, untill a colleage pointed me to: Capabilities.playerType.
Greetz Erik
Greetz Erik
This is what I use:
trace(System.capabilities.playerType);
returns:
"StandAlone" for the Flash StandAlone Player
"External" for the Flash Player version used by the external player, or test movie mode
"PlugIn" for the Flash Player browser plug-in
"ActiveX" for the Flash Player ActiveX Control used by Microsoft Internet Explorer
trace(System.capabilities.playerType);
returns:
"StandAlone" for the Flash StandAlone Player
"External" for the Flash Player version used by the external player, or test movie mode
"PlugIn" for the Flash Player browser plug-in
"ActiveX" for the Flash Player ActiveX Control used by Microsoft Internet Explorer
return new LocalConnection( ).domain == "localhost";
More domain functions can be found on:
http://code.google.com/p/braemar/source/browse/trunk/src/org/braemarframework/utils/DomainUtils.as
More domain functions can be found on:
http://code.google.com/p/braemar/source/browse/trunk/src/org/braemarframework/utils/DomainUtils.as
var localMode : Boolean = loaderInfo.url.indexOf("http:\\www.file.com") == 0;
an another way:
static public const LOCAL:Boolean = Security.sandboxType != Security.REMOTE;
static public const LOCAL:Boolean = Security.sandboxType != Security.REMOTE;
@Patrick Pietens
then check for 'file:///'.. Thats how we used to do it.
then check for 'file:///'.. Thats how we used to do it.
or you could just unplug the cable and see if it works :P
var noob:NoConnection = Cabble.status();
var noob:NoConnection = Cabble.status();
I second the playerType approach, BUT that technically only determines if you're in a browser or not (and if not, that usually means the Flash IDE, but I suppose it works for stand-alone debug mode). It's possible you just opened up the HTML page containing the SWF in a browser, without it being served up on HTTP. In that case, the "indexOf file" trick still correctly determines if you are local or not.
I depends on your needs, I guess. Do you want to determine if you're in a browser or not, or if you're on a web server or not?
I depends on your needs, I guess. Do you want to determine if you're in a browser or not, or if you're on a web server or not?
Along those lines, I often have a Main movie and a Preloader movie, and I want the Main movie to run either by itself (for debugging) or inside a Loader when it's preloaded. So I kick everything off for Main through a public init() function, and in Main's constructor, I check:
if( !loaderInfo.loader ) {
init();
}
if( !loaderInfo.loader ) {
init();
}
if (Capabilities.playerType != 'ActiveX' && Capabilities.playerType != 'PlugIn' ) {
}
works great
}
works great
var localMode : Boolean = loaderInfo.url.indexOf("file") == 0;
What happens if your SWF file URL is something like: "http://mywebsite.com/files/foo.swf"?
If you use this option you would be safer to do it like:
var localMode : Boolean = loaderInfo.url.indexOf("file://") == 0;
What happens if your SWF file URL is something like: "http://mywebsite.com/files/foo.swf"?
If you use this option you would be safer to do it like:
var localMode : Boolean = loaderInfo.url.indexOf("file://") == 0;
If the URL were "http://mywebsite.com/files/foo.swf" then indexOf will return 21 ;)
Hmm. each and every method above had an issue...
loaderInfo.url.indexOf("file") == 0;
TypeError: Error #1009: Cannot access a property or method of a null object reference.
trace(System.capabilities.playerType);
Warning: 1058: Migration issue: The property capabilities is no longer supported. The capabilities class has been renamed Capabilities..
trace(System.Capabilities.playerType);
ReferenceError: Error #1065: Variable System::Capabilities is not defined.
trace( Security.sandboxType , Security.REMOTE );
ReferenceError: Error #1065: Variable Security is not defined.
loaderInfo.url.indexOf("file") == 0;
TypeError: Error #1009: Cannot access a property or method of a null object reference.
trace(System.capabilities.playerType);
Warning: 1058: Migration issue: The property capabilities is no longer supported. The capabilities class has been renamed Capabilities..
trace(System.Capabilities.playerType);
ReferenceError: Error #1065: Variable System::Capabilities is not defined.
trace( Security.sandboxType , Security.REMOTE );
ReferenceError: Error #1065: Variable Security is not defined.
Are you trying them on flash5 or something? :P
fixed, was trying to use them within a class. works just fine on the timeline before the class initialises, so that's probably the best place to be doing this anyway.
This doesn't help against Crackers that try to hack my highscore does it? ..well maybe it's a little obstacle more.
PlayerType is fine if you are testing in CS4 in the Flash player but in Flex you'll be in the browser ... Dooby's method is the simplest way of detecting if you're online unless you are deploying to a server.
Have your say!
*profile

traditional id: Ricardo Cabello Miguel
based in: London, UK
more: github, twitter, twitpic, soundcloud and flattr
*post nav
Receptor - Rhyno
Good old Plasma effect
Things I still miss in Ubuntu
Get the amount of files in a folder with Ubuntu
Install debug version of Flash Player plugin in Ubuntu
Detect if the swf is being executed localy or online
Sys-Con now attacks Mr.doob!
Chrome Experiments!
Face tracking + 3D Scene, Laughing Man, DOF Tunel and more...
navigateToURLAndUpdateStageSize()
png2swf.jsfl & folder_png2swf.jsfl v1.2
*latest comments
Merry Xmas
Multiuser Sketchpad
Multiuser Sketchpad
Or so they say... (javascript demo)
Multiuser Sketchpad
Or so they say... (javascript demo)
Or so they say... (javascript demo)
Or so they say... (javascript demo)
Or so they say... (javascript demo)
Harmony