Author Archives: Zevan

String.fromCharCode()

CLICK HERE TO COPY
Actionscript:

[SWF(height = 950, width=1000)]

var txt:TextField;

var num:int = 0;

for (var i:int = 0; i<761; i++){

    if (i % 76 == 0){

         makeTxt(num);

         num++;

    }

    if (i <0x21){

        txt.appendText("-\n");

    }else{

        txt.appendText(String.fromCharCode(i) + " = " +  i + [...]

Posted in strings | Tagged , | Leave a comment

String.localeCompare()

CLICK HERE TO COPY
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 , | Leave a comment

Random Sort

CLICK HERE TO COPY
Actionscript:

function randomize(a:*, b:*):int{

       return Math.round(Math.random()*8) - 4;

}

 

var i:int;

var fruits:Array;

 

trace("Math.random()");

for (i = 0; i<4; i++){

  // reset fruits array:

  fruits = ["apple", "grape","pear","cherry"];

  fruits.sort(randomize);

  trace(fruits);

}

 

 

// seeds

var s1:Number= 0xFF00FF;

var s2:Number = 0xCCCCCC;

var s3:Number= 0xFF00F0;

 

function tRandomize(a:*, b:*):int{

       return Math.round(rand()*8) - 4;

}

 

trace("\nTausworthe rand()");

for (i= 0; i<4; i++){

  fruits = ["apple", "grape","pear","cherry"];

  fruits.sort(tRandomize);

  [...]

Posted in arrays, misc | Tagged , | Leave a comment

String.indexOf()

CLICK HERE TO COPY
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". [...]

Posted in string manipulation, strings | Tagged , | Leave a comment