ActionScript Standard Library project is really picking up. For those who are hearing it for the first time, the ActionScript Standard Library is a collection of ActionScript classes and libraries that aims to create and provide a standard library of functionality to ActionScript. ASL is an Open Source initiative by Mike Chambers, the community manager of macromedia.

Currently 33 developers (including me) started putting in their efforts. If you want to get updated with the latest development about that project you can visit the forum and/or subscribe to the mailing list.

We are going to start with extending String, Date, Math Objects and then proceed to other complex Objects.

Here are some of my ideas to extend the String object.

Title Case:

[cc lang=”actionscript3″]String.prototype.toTitleCase = function() { var str = “”; var prevWhite = true; for (var i = 0; i<this.length; i++) { str += prevWhite ? this.charAt(i).toUpperCase() : this.charAt(i).toLowerCase(); prevWhite = this.charCodeAt(i)<=32; } return str; }; [/cc]

Example:

[cc lang=”actionscript3″]trace(“message to the universe of girls: i’m having a mechanical life here 🙁“.toTitleCase()); //outputs ‘Message To The Universe Of Girls: I’m Having A Mechanical Life Here :(‘ [/cc]

Sentence case:
[cc lang=”actionscript3″]String.prototype.toSentenceCase = function() { var str = “”; var SentenceBrake = true; for (var i = 0; i<this.length; i++) { str += SentenceBrake ? this.charAt(i).toUpperCase() : this.charAt(i).toLowerCase(); SentenceBrake = (SentenceBrake && this.charCodeAt(i)<=32) || “rn.,?:;!“.indexOf(this.charAt(i)) != -1; } return str; }; [/cc]

Example:

[cc lang=”actionscript3″]trace(“i’m searching for my soul mate. if you feel you are the one (at least try to feel like that)“.toSentenceCase()); // outputs ‘I’m searching for my soul mate. If you feel you are the one (at least try to feel like that)’ tOGGLE cASE:

String.prototype.toToggleCase = function() {
        var str = "";
        for (var i = 0; i<this.length; i++) {
                str += this.charCodeAt(i)<=90 ? this.charAt(i).toLowerCase() : this.charAt(i).toUpperCase();
        }
        return str;
};
[/cc]
		

Example:
[cc lang="actionscript3"]trace("i'M wAITING fOR yOU, dO dROP mE a mAIL".toToggleCase()); //outputs 'I'm Waiting For You, Do Drop Me A Mail' [/cc]

Single Space: - Clears the extra spaces and line brakes in the given String
[cc lang="actionscript3"]String.prototype.toSingleSpace = function() { var str = ""; var prevWhite = true; for (var i = 0; i<this.length; i++) { var code = this.charCodeAt(i); white = code<=32; if (white) { if (!prevWhite && (code == 9 || code == 32)) { str += " "; } } else { str += this.charAt(i); } prevWhite = white; } return str; }; [/cc]

Example:
[cc lang="actionscript3"]trace("I have waited for you so rl o n g n !".toSingleSpace()); //outputs 'I have waited for you so l o n g !' //note:- // the text used in the examples is just for fun, // should not be taken seriously [except by the willing girl(s!?)][/cc]