Avatar
💡
  • Simple class that loads config files. You can view the documentation here. This is provided as is, but please post any errors, corrections or suggestions in the comments below.

    #include "stringUtils.as"
    
    /*
     Config.as v1.0
    
     created by mike chambers : <A href="mailto:mesh@macromedia.com">mesh@macromedia.com</A>
    
     requires stringUtils.as which can be downloaded from:
     http://www.mikechambers.com/files/mesh/files/stringutils/
    
    */
    if (!String.stringUtilsDefined) {
        trace("Warning : The stringUtils.as file was not loaded. This library is required " +
            "by the Config.as file. Please make sure that the stringUtils.as file is " +
            "either in the same directory as the Config.as file, or is included in the " +
            "Flash MX include path.");
    }
    
    if (String.stringUtilsVersion & lt; 1.5) {
        trace("Warning : Config.as requires the stringUtils.as version 1.5 or higher. " +
            "You are using version : " + String.stringUtilsVersion +
            " Please upgrade your stringUtils.as file.");
    }
    
    
    /*
     Constructor that takes the path to the config file as an argument
    
     Path can be any valid relative or absolute file or url path. Although if
     running from a browser,  Flash's security restrictions apply.
    */
    _global.Config = function (fileName) {
        this.fileName = fileName;
    }
    
    
    
    /*
     Method that allows you to set the path to the config file.
    
     Path can be any valid relative or absolute file or url path. Although if
     running from a browser,  Flash's security restrictions apply.
    */
    Config.prototype.setFileName = function (fileName) {
        this.fileName = fileName;
    }
    
    
    
    /*
     Returns a string of the path to the current config file.
    
     If a config file has not been specified, then it returns null;
    */
    Config.prototype.getFileName = function () {
        return this.fileName;
    }
    
    
    
    /*
     Method which takes a boolean value that indicates whether
     or not double quotes surrounding names and values should be removed.
    
     Default is false.
    */
    Config.prototype.setStripQuotes(strip) {
        this.stripQuotes = strip;
    }
    
    
    
    /*
     Method which takes a boolean value that indicates whether
     or not values that contain commas should be exploded into
     an array of values.
    
     If set to true, calling get() on the name will return an Array.
    
     If set to false, calling get() on the name will return a string.
    
     The default is false.
    */
    Config.prototype.setExplodeValues(explode) {
        this.explodeValues = explode;
    }
    
    
    Config.prototype.onData = function (data) {
        if (this.parse(data)) {
            this.onConfigLoad(true);
        } else {
            this.loaded = false;
            this.onConfigLoad(false);
        }
    
    }
    
    
    
    /*
     This is a convenience method that allows you to pass a string
     representing a config file to be parsed.
    
     It returns true if the parsing succeeded, and false if it did not.
    
     Note, since the method returns immediately, you may access
     the data in the object immediately after it has returned true.
    
     For example:
    
     var c = new Config();
     var s = "foo=bar\n";
     s += "name = mike\n";
    
     if(c.parse(s))
     {
      trace(c.get("foo"));    //traces "bar"
     }
    
     If the config object has already parsed data, then the new data will be added
     to the config object, overwriting any duplicate values that already exist.
    */
    Config.prototype.parse = function (data) {
    
        var rows = data.split("\n");
        var rLength = rows.length;
        var tArray = new Array();
    
        var rString;
        var tName;
        var tString;
        var c;
    
        for (var i = 0; i & lt; rLength; i++) {
            rString = rows[i];
    
            c = rString.charAt(0);
    
            if (c == ";" || c == "#" ||
                c == "[" || c == "/") {
                continue;
            }
    
            tArray = rString.split("=");
    
            if (tArray.length != 2) {
                continue;
            }
    
            tName = tArray[0].trim();
            tValue = tArray[1].trim();
    
            //maybe write custom loop to strip the quotes in one pass.
            if (this.stripQuotes) {
                if (tValue.beginsWith("\"")) {
                    tValue = tValue.substring(1);
    
                    if (tValue.endsWith("\"")) {
                        tValue = tValue.substring(0, tValue.length - 1);
                    }
                }
    
                if (tName.beginsWith("\"")) {
                    tName = tName.substring(1);
    
                    if (tName.endsWith("\"")) {
                        tName = tName.substring(0, tName.length - 1);
                    }
                }
            }
    
            if (this.explodeValues) {
                if (tValue.indexOf(",") & gt; 0) {
                    //we jsut changed tValue from a string to array;
                    tValue = tValue.split(",");
                }
            }
    
            this.configArray[tName] = tValue;
    
            tValue = null;
            tName = null;
        }
    
        this.loaded = true;
        return true;
    }
    
    
    
    /*
     Takes a string and returns the value for that name in the config file.
    
     For example:
    
     config.ini
     foo=bar
     name=mike
    
     var c = new Config("config.ini");
    
     c.onConfigLoad = function(success)
     {
      trace(c.get("foo"));         //traces "bar"
      trace(c.get("name"));     //traces "mike"
     }
    */
    Config.prototype.get = function (hash) {
        return this.configArray[hash];
    }
    
    
    
    /*
     Returns an associative array containing the name value
     pairs contained within the object.
    */
    Config.prototype.getArray = function () {
        return this.configArray;
    }
    
    /*
     This method loads the config file specified in the constructor or
     setConfigFile() method, and then parses it.
    
     Once it has been parsed, the onConfigLoad() method will be
     called and passed a boolean value indicating whether the
     file was able to be parsed.
    
     The onConfigLoad method should be over ridden in order to
     allow the developer to know when the data has loaded and been parsed.
    */
    Config.prototype.loadConfig = function () {
        this.loaded = false;
        this.load(this.fileName);
    }
    
    /*
     Default values for internal variables within the object.
    */
    Config.prototype.configArray = new Array();
    Config.prototype.stripQuotes = false;
    Config.prototype.explodeValues = false;
    
    /*
     this indicates whether or not the data has loaded. you should be
     able to register with with a watch method.
    */
    Config.prototype.loaded = false;
    Config.prototype.fileName = null;
    
    /* Extending the LoadVars object. */
    Config.prototype.__proto__ = LoadVars.prototype;
    Config.prototype.superClass = LoadVars.prototype.constructor;
    
    Config.prototype.constructor.configDefined = true;
    Config.prototype.constructor.configVersion = 1.0;
    
    actionscript Created Tue, 14 May 2002 12:40:01 +0000
  • I don’t have much to post this morning, so I posted some ActionScript code that I created when I first started to play around with Flash MX. I have posted two things:

    • Config.as - This is a class that can load and parse config files of various formats.
    • stringUtils.as - This is a library that adds useful methods to the String object.

    Note, these are provided as is. Also, there is some weird stuff in there (look how I check that Config.as is included, I should just check for Config.prototype). If you have any comments, or suggestions, be sure to post them in the comments section for each piece of code.

    actionscript Created Tue, 14 May 2002 12:34:01 +0000
  • Simple library that adds useful methods to the String object. You can view the documentation here. This is provided as is, but please post any errors, corrections or suggestions in the comments below.

    Download here

    /*String Utility Component version 1.5
    
    Mike Chambers
    
    thanks to Branden Hall, Ben Glazer, Christian Cantrell, Nik Schramm
    */
    
    /* This allows user to check from other include files whether or not the stringUtils library has been included.
    
    Example:
    if(!String.stringUtilsDefined) {
    	trace("stringUtils.as not found");
    }
    */
    
    String.prototype.constructor.stringUtilsDefined = true;
    String.prototype.constructor.stringUtilsVersion = 1.5;
    
    /*** This methods trims all of the white space from the left side of a String.*/String.prototype.ltrim = function() {
    
    var size = this.length;
    	for(var i = 0; i <; size; i++) {  if(this.charCodeAt(i) > 32)
     	{
    		return this.substring(i);  }
    	}
    	return "";
    }
    
    /*** This methods trims all of the white space from the right side of a String.*/String.prototype.rtrim = function(){
    	var size = this.length;
    	for(var i = size; i > 0; i-) {
    		if(this.charCodeAt(i) > 32)  {
    			return this.substring(0, i + 1);
    		}
    	}
    	return "";
    }
    
    /*** This methods trims all of the white space from both sides of a String.*/
    String.prototype.trim = function(){
    	return this.rtrim().ltrim();
    }
    
    /*** This methods returns true if the String begins with the string passed into* the method. Otherwise, it returns false.*/
    String.prototype.beginsWith = function(s) {
    	return (s == this.substring(0, s.length));
    };
    
    /*** This methods returns true if the String ends with the string passed into* the method. Otherwise, it returns false.*/
    String.prototype.endsWith = function(s) {
    	return (s == this.substring(this.length - s.length));
    };
    
    
    
    String.prototype.remove = function(remove){
    	return this.replace(remove, "");
    }
    
    String.prototype.replace = function(replace, replaceWith){
    	sb = new String();
    	found = false;
    	for (var i = 0; i < this.length; i++) {
    		if(this.charAt(i) == replace.charAt(0)) {
    			found = true;
    			for(var j = 0; j < replace.length; j++) {
    				if(!(this.charAt(i + j) == replace.charAt(j))) {
    					found = false;
    					break;
    				}
    			}
    			if(found) {
    				sb += replaceWith;
    				i = i + (replace.length - 1);
    				continue;
    			}
    		}
    		sb += this.charAt(i);
    	}
    	return sb;
    }
    
    actionscript Created Tue, 14 May 2002 12:18:01 +0000
  • The tech note describing using eval on the left side of an operator has been updated to take note of an issue that has arisen.

    eval("TextField" + "One") = "string1″
    trace("TextFieldOne")
    

    Will return “undefined” in Test Movie and the eval() will fail in Macromedia Flash Player 6.

    To correct the problem enclose the string concatenation in an extra set of parentheses:

    eval(("TextField" + "One")) = "string1″;
    

    You can find more info on eval in this post.

    Created Tue, 14 May 2002 12:15:01 +0000
  • Slashdot posted an article with concerns about privacy and security in the Flash player due to the players access to a user’s camera, microphone and its ability to store data (via shared objects). Below is some information and links which will hopefully dispel some of the misperceptions in the original article and in some of the comments attached to the article .

    The Camera and Microphone access defaults to off. Anytime that a Flash movie tries to access the camera or microphone the user will be asked to allow or deny the access. The access is domain based.

    Created Mon, 13 May 2002 12:54:01 +0000
  • Macromedia JRun 4 was announced today. JRun 4 is a J2EE 1.3 Compatible server for deploying Java applications. Among its new features, is the inclusion of Flash Remoting.

    JRun 4 comes with some Flash Remoting samples. However, be sure to first read the known issues document.

    You can view a diagram of how Flash Remoting fits in with the JRun architecture here.

    Created Mon, 13 May 2002 12:34:01 +0000
  • Dave Yang has put up a ServerSide ActionScript / Flash Remoting example that lists all of the functions and properties of the ServerSide ActionScript CF object. This is similar to the example i posted the other day, except Dave’s example provides more information and is a little more elegant (I like how Dave organizes his NetServices code).

    You can view the example here.

    Created Sat, 11 May 2002 12:56:01 +0000
  • Joey Lott sent along an example that shows how to find some undocumented properties of the CF object in ServerSide ActionScript.

    You can view the example here.

    Created Fri, 10 May 2002 12:59:01 +0000
  • I was looking through the directory of web services at xmethods.net, and found a web service that provides stock quotes. I put together a simple example that shows how to call the web service from Flash via Flash Remoting.

    You can view the example here.

    Created Fri, 10 May 2002 12:51:01 +0000
  • This is a simple Flash example that calls a Stock quote web service via Flash Remoting. You can find more info on the web service being used below at xmethods.net.

    1. Download and install the ColdFusion MX preview release.
    2. Download and install the Flash Remoting add-ons for Flash MX.
    3. Create a new Flash movie and enter the the following code in the first frame of the movie.
    #include "NetServices.as"
    
    var params = new Object();
    
    //this is always 0, and is specific to the web service.
    params.LicenseKey = "0″;
    
    //stock symbol we want information about
    params.StockSymbol = "macr";
    
    //create an object to catch the response from the web service
    var result = new Object();
    
    //data is an object which contains properties with information about the stock.
    result.onResult = function(data)
    {
    	//loop through all of the properties and print them out
    	for(var x in data)
    	{
    		trace(x + " : " + data[x]);
    	}
    }
    
    //this gets called if an error occurs.
    result.onStatus = function(error)
    {
    	//print out the error
    	trace("Error : " + error.description);
    }
    
    //the path to the web service’s WSDL file.
    var webServiceWSDL = "http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?wsdl";
    var gw = NetServices.createGatewayConnection("http://localhost:8500/flashservices/gateway/");
    var service = gw.GetService(webServiceWSDL, result);
    
    //call a method on the web service, passing params.
    service.GetQuote(params);
    

    Test the movie. You should see the data from the web service print in the Output window.

    Created Fri, 10 May 2002 12:51:01 +0000