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:
  1. /**
  2. * 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.
  3. *
  4. * @author Matt Przybylski [http://www.reintroducing.com]
  5. * @version 1.0
  6. */
  7.  
  8. class com.reintroducing.debug.Environment
  9. {
  10.     //- PRIVATE VARIABLES -------------------------------------------------------------------------------------
  11.     
  12.     // singleton instance
  13.     private static var _instance:Environment;
  14.    
  15.     private var _debugPath:String;
  16.     private var _livePath:String;
  17.     private var _basePath:String;
  18.     private var _isLive:Boolean;
  19.    
  20. //- PUBLIC VARIABLES --------------------------------------------------------------------------------------
  21.    
  22.    
  23.    
  24. //- CONSTRUCTOR -------------------------------------------------------------------------------------------
  25.    
  26.     // singleton instance of Environment
  27.     public static function getInstance():Environment
  28.     {
  29.         if (Environment._instance == null) Environment._instance = new Environment();
  30.         return Environment._instance;
  31.     }
  32.    
  33.     private function Environment()
  34.     {
  35.        
  36.     }
  37.    
  38. //- PRIVATE METHODS ---------------------------------------------------------------------------------------
  39.    
  40.     private function setProperPath():Void
  41.     {
  42.         if (System.capabilities.playerType == "PlugIn" || System.capabilities.playerType == "ActiveX")
  43.         {
  44.             this._basePath = this._livePath;
  45.             this._isLive = true;
  46.         }
  47.         else
  48.         {
  49.             this._basePath = this._debugPath;
  50.             this._isLive = false;
  51.         }
  52.     }
  53.    
  54. //- PUBLIC METHODS ----------------------------------------------------------------------------------------
  55.    
  56.     /**
  57.      * Sets the proper debug/live paths.
  58.      *
  59.      * @param $debugPath A string representing the local (debug) path
  60.      * @param $livePath A string representing the remote (live) path
  61.      *
  62.      * @return void
  63.      */
  64.     public function setPaths($debugPath:String, $livePath:String):Void
  65.     {
  66.         this._debugPath = $debugPath;
  67.         this._livePath = $livePath;
  68.        
  69.         this.setProperPath();
  70.     }
  71.    
  72. //- EVENT HANDLERS ----------------------------------------------------------------------------------------
  73.    
  74.    
  75.    
  76. //- GETTERS & SETTERS -------------------------------------------------------------------------------------
  77.    
  78.     /**
  79.      * Returns the basePath for use in loading assets.
  80.      *
  81.      * @return String
  82.      */
  83.     public function get basePath():String
  84.     {
  85.         return this._basePath;
  86.     }
  87.    
  88.     /**
  89.      * Returns a Boolean value if the site is on a live server or being tested locally.
  90.      *
  91.      * @return Boolean
  92.      */
  93.     public function get isLive():Boolean
  94.     {
  95.         return this._isLive;
  96.     }
  97.    
  98. //- HELPERS -----------------------------------------------------------------------------------------------
  99.    
  100.     public function toString():String
  101.     {
  102.         return "com.reintroducing.debug.Environment";
  103.     }
  104.    
  105. //- END CLASS ---------------------------------------------------------------------------------------------
  106. }

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

(required)

(required)