AS2: Environment
View Documentation
Download Class
A small utility class that allows you to set debug and live path variables for local and remote testing without having to toggle anything.
This is the same as my AS3 version except just re-purposed for use in AS2.
Actionscript:
-
/**
-
* A small Singleton utility class that allows you to set debug and live path variables for local and remote testing without having to toggle anything.
-
*
-
* @author Matt Przybylski [http://www.reintroducing.com]
-
* @version 1.0
-
*/
-
-
class com.reintroducing.debug.Environment
-
{
-
//- PRIVATE VARIABLES -------------------------------------------------------------------------------------
-
-
// singleton instance
-
private static var _instance:Environment;
-
-
private var _debugPath:String;
-
private var _livePath:String;
-
private var _basePath:String;
-
private var _isLive:Boolean;
-
-
//- PUBLIC VARIABLES --------------------------------------------------------------------------------------
-
-
-
-
//- CONSTRUCTOR -------------------------------------------------------------------------------------------
-
-
// singleton instance of Environment
-
public static function getInstance():Environment
-
{
-
if (Environment._instance == null) Environment._instance = new Environment();
-
return Environment._instance;
-
}
-
-
private function Environment()
-
{
-
-
}
-
-
//- PRIVATE METHODS ---------------------------------------------------------------------------------------
-
-
private function setProperPath():Void
-
{
-
if (System.capabilities.playerType == "PlugIn" || System.capabilities.playerType == "ActiveX")
-
{
-
this._basePath = this._livePath;
-
this._isLive = true;
-
}
-
else
-
{
-
this._basePath = this._debugPath;
-
this._isLive = false;
-
}
-
}
-
-
//- PUBLIC METHODS ----------------------------------------------------------------------------------------
-
-
/**
-
* Sets the proper debug/live paths.
-
*
-
* @param $debugPath A string representing the local (debug) path
-
* @param $livePath A string representing the remote (live) path
-
*
-
* @return void
-
*/
-
public function setPaths($debugPath:String, $livePath:String):Void
-
{
-
this._debugPath = $debugPath;
-
this._livePath = $livePath;
-
-
this.setProperPath();
-
}
-
-
//- EVENT HANDLERS ----------------------------------------------------------------------------------------
-
-
-
-
//- GETTERS & SETTERS -------------------------------------------------------------------------------------
-
-
/**
-
* Returns the basePath for use in loading assets.
-
*
-
* @return String
-
*/
-
public function get basePath():String
-
{
-
return this._basePath;
-
}
-
-
/**
-
* Returns a Boolean value if the site is on a live server or being tested locally.
-
*
-
* @return Boolean
-
*/
-
public function get isLive():Boolean
-
{
-
return this._isLive;
-
}
-
-
//- HELPERS -----------------------------------------------------------------------------------------------
-
-
public function toString():String
-
{
-
return "com.reintroducing.debug.Environment";
-
}
-
-
//- END CLASS ---------------------------------------------------------------------------------------------
-
}
If you found this post useful, please consider leaving a comment, subscribing to the feed, or making a small donation.













No Comments
No comments yet.
Leave a comment