Avatar
💡
41 results for Actionscript
  • As part of the ActionScript 2 Atom class that I am putting together, I have created an ActionScript class that represents a W3CDateTime string. This is the format that Atom uses to represent dates.

    A beta of the class and simple usage example is included below. If you have any questions or suggestions (especially parsing optimizations), or find any bugs, please post them in the comments.

    Here is a simple example of the class in use:

    actionscript Created Fri, 06 Feb 2004 12:47:01 +0000
  • One of the issues I ran into while building the MXNA WebService example app, was that both the ComboBox and DataGrid both broadcast “change” events. This meant that I could not have a separate function to listen for each event (and have the functions run within the scope of the feedView class).

    There were two solutions to this. The first was to have a switch statement in my change event handler, that checked the eventObt.target property to see where the event came from. I could then dispatch the call as appropriate. Here is an example of what the event handler would look like:

    actionscript Created Wed, 28 Jan 2004 12:42:01 +0000
  • If you have used the Central trace panel, you may have noticed the “App Name Filter” text field in the bottom left of the panel. This is used to filter trace messages coming from Central so you only see messages coming from your application.

    So, how do you use this? It is actually pretty simple.

    First, you need to set a global variable in your App / Agent / Pod that tells Central your application name. This is done using:

    central actionscript Created Fri, 12 Dec 2003 12:03:01 +0000
  • A question was posted to my weblog asking how to retrieve the data for the individual bar chart section selected in the 3D Bar chart included as part of the Flash Charting Components Set 2 on DRK 4.

    If you are using a listener to capture the select / press event, it is very simple as all of the data is passed to the listener method.

    Here is an example:

    actionscript Created Mon, 11 Aug 2003 12:35:01 +0000
  • One of the big hassles of developing with ActionScript is that when trying to access properties and functions that do not exist, the Flash IDE does not throw an error. This can make it very difficult to debug code that is not working due to something as simple as a misspelled variable name.

    Below is some simple code that shows how to trace errors when your code tries to access properties / functions that do not exist.

    actionscript Created Tue, 03 Jun 2003 12:42:01 +0000
  • One of the requests that I got for the Google search application that Josh Dura and I have been working on, is to give the user the option to open links in a new window. This makes sense, since if you leave the page, the Flash application looses its state. Well, I added an option in the settings panel to always open links in a new window, but I decided to also add support for SHIFT or CTRL clicking a link to open it in a new window (since a lot of people do this out of habit now.)

    actionscript Created Mon, 05 May 2003 12:48:01 +0000
  • I have received a couple of emails over the past couple of days, asking how to manually loop through a RecordSet / DataProviderClass. It is actually pretty simple and utilizes the getItemAt() and getLength() methods of the DataProviderClass (pseudo interface).

    Here is the code:

    //rs is a RecordSet object retrieved via FlashRemoting
    
    var len = rs.getLength();
    var tmpObj;
    
    for(var i = 0; i < len; i++)
    {
    	tmpObj = rs.getItemAt(i);
    	trace("Field 1 : " + tmpObj.field1);
    	trace("Field 2 : " + tmpObj.field2);
    }
    

    This will work for all RecordSet and DataProviderClass classes.

    actionscript Created Fri, 14 Feb 2003 12:37:01 +0000
  • 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