By Zevan | February 28, 2009
Actionscript:
-
var letterA:String = "a";
-
var letterZ:String = "z";
-
-
trace(letterA.localeCompare(letterZ));
-
trace(letterZ.localeCompare(letterA));
-
/*
-
outputs
-
-25
-
25
-
*/
String.localeCompare() calculates the sorting order between two Strings....
Posted in strings | Tagged actionscript, flash |
By Zevan | February 26, 2009
Actionscript:
-
var words:String = "one two three four five";
-
-
trace("two: ", words.indexOf("two"));
-
-
var letters:String = "abcd";
-
-
trace("d: ",letters.indexOf("d"));
-
-
trace("z: ",letters.indexOf("z"));
-
-
/*
-
outputs:
-
two: 4
-
d: 3
-
z: -1
-
*/
indexOf() searches a string for another string and returns an index... in line 3 above, I search the words string for the smaller string "two" and indexOf() gives me the index of the letter "t". If indexOf() doesn't find anything it will return -1 (as in the case of line 9).
I seem to recall using this in some unexpected places. I'll see if I can dig up an example over the next few days.
By Zevan | February 25, 2009
Actionscript:
-
var txt:TextField = TextField(addChild(new TextField()));
-
txt.text = "";
-
txt.width = 190;
-
txt.height = 400;
-
txt.multiline = true;
-
-
var count:int = 1;
-
function render():void{
-
var line = int(count).toString(2);
-
while(line.length <31){
-
line = "0" + line;
-
}
-
txt.appendText(line + "\n");
-
txt.scrollV= txt.maxScrollV;
-
}
-
-
addEventListener(Event.ENTER_FRAME, onCountUp);
-
function onCountUp(evt:Event):void {
-
count *= 2;
-
render();
-
if (count ==0x40000000){
-
removeEventListener(Event.ENTER_FRAME, onCountUp);
-
addEventListener(Event.ENTER_FRAME, onCountDown);
-
}
-
}
-
function onCountDown(evt:Event):void {
-
count /= 2;
-
render();
-
if (count ==1){
-
addEventListener(Event.ENTER_FRAME, onCountUp);
-
removeEventListener(Event.ENTER_FRAME, onCountDown);
-
}
-
}
The above animates a zig zag pattern in a TextField.
By Zevan | February 15, 2009
C:
-
SELECT * FROM _users WHERE SOUNDEX(name) LIKE SOUNDEX('jon');
Not ActionScript, but the coolest thing I've seen in Mysql in awhile, the soundex function will convert a string into a soundex index... read more about it on wikipedia.
I did some tests and it matches things like:
what's your name? & whats yer name
very cool... since this isn't ActionScript, I will post another snippet right after this.
UPDATE: Actually started reading more about this stuff and dug up some algorithms... metaphone etc... fun stuff, maybe I'll port some of it to actionscript...