I used to use that, untill a colleage pointed me to: Capabilities.playerType.
Greetz Erik
April 2nd 2009
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
then check for 'file:///'.. Thats how we used to do it.
April 3rd 2009
Fedlarm
or you could just unplug the cable and see if it works :P
var noob:NoConnection = Cabble.status();
April 3rd 2009
am (noob)
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?
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();
}
April 3rd 2009
RoomsInJars
if (Capabilities.playerType != 'ActiveX' && Capabilities.playerType != 'PlugIn' ) {
}
works great
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.
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.
April 20th 2009
mr noob worked it ou
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.