Script

Filter
2006-02-14

Globala funktioner

Javascript
Globala funktioner i javascript
escape
This function takes a string argument and returns it encoded in a hexadecimal format

unescape
This function takes a string as its argument and returns a string in which all characters
previously encoded with escape are decoded.

eval
This function takes a string argument representing JavaScript code to execute.

isFinite
This function takes a numeric argument and returns true if the value of the argument
is not NaN, Number.POSITIVE_INFINITY or Number.NEGATIVE_INFINITY; 

isNaN
This function takes a numeric argument and returns true if the value of the argument is not a number;
otherwise, the function returns false. The function is commonly used with the return value of parseInt
or parseFloat to determine whether the result is a proper numeric value.

parseFloat
This function takes a string argument and attempts to convert the beginning of the string into a floating-point value.

parseInt
This function takes a string argument and attempts to convert the beginning of the string into an integer value.
This function takes an optional second argument, from 2 to 36, specifying the radix (or base) of the number.
2006-02-14

Switch

Javascript
Switch med flera alternativ
switch ( sumOfDice ) {
    case 7: case 11:
        gameStatus = WON;
        myPoint = 0;
        break;
    case 2: case 3: case 12:
        gameStatus = LOST;
        break;
    default:
        gameStatus = CONTINUE_ROLLING;
        myPoint = 0;
        myPoint = sumOfDice;
} 
2006-02-14

Using the continue Statement with a Label

Javascript
Använd en label för att styra en loop
<script type = "text/javascript">
nextRow:   // target label of continue statement
    for ( var row = 1; row <= 5; ++row ) {
        document.writeln( "<br />" );
        for ( var column = 1; column <= 10; ++column ) {
            if ( column > row )
                continue nextRow; // next iteration of labeled loop
            document.write( "* " );
        }
    }
</script> 
2006-02-14

Label compound statement

Javascript
Använd namngivna block t ex för att förflytta i en control structure
<script>
stop: {
    for (var row = 1; row <= 10; ++row) {
        for (var column = 1; column <= 5 ; ++column) {
            if (row == 5 )
                break stop; // jump to end of stop block
            document.write("* ");
        }
        document.writeln( "<br />");
    }
    document.writeln( "This line should not print" );
}
</script> 
2006-02-13

Bilder med runda hörn

Flash
Runda av hörnen med actionscript
var w:Number = Stage.width;
var h:Number = Stage.height;
var radie = parseInt(radie);
if (isNaN(radie)) { radie = 20; }
var col = parseInt(color, 16);
if (isNaN(col)) { col = 0xffffff; }
function drawCorner(sMc, p1:Object, p2:Object, p3:Object, col:Number):Void {
    var mc:MovieClip = this.createEmptyMovieClip(sMc, this.getNextHighestDepth());
   mc.lineStyle(0, col, 0); // hairline, transparent
   mc.beginFill(col, 100); // opaque
   mc.moveTo(p1.x, p1.y);
   mc.lineTo(p2.x, p2.y);
   mc.lineTo(p3.x, p3.y);
   mc.curveTo(p2.x, p2.y, p1.x, p1.y); // ctrlpoint, destpoint
   mc.endFill();
}
drawCorner ("TL", {x:0, y:radie}, {x:0, y:0}, {x:radie, y:0}, col);
drawCorner ("TR", {x:w-radie, y:0}, {x:w, y:0}, {x:w, y:radie}, col);
drawCorner("BR",{x:w, y:h-radie},{x:w, y:h},{x:w-radie, y:h},col);
drawCorner("BL",{x:radie, y:h},{x:0, y:h},{x:0, y:h-radie},col); 
🙂