28.9.10

Sine

Here is another error I had when creating a function that utilize the Sine function in Actionscript 3.0.


function FindSin(Fin:Number):Number {
    var Truest1 = Fin * Math.sin;
    return Truest1;
}




trace(FindSin(115));


When I ran this code, I got a particular error message. 

Scene 1, Layer 'Layer 1', Frame 1, Line 2 1067: Implicit coercion of a value of type Function to an unrelated type Number.

When I read this error message, I over-thought the issue and immediately began doing things like this, thinking it was a syntax or convention issue and not a logic issue. 

function FindSin(Fin:Number):Number {
    var Truest1:Number = Fin * Math.sin;
    return Truest1;
}


trace(FindSin(115));

No solution there. It wasn't until I actually started writing this post that I realized what the error message really meant: "You are trying to turn a function into a number; stop doing that". I immediately started fidgeting with the FindSin function and it's parameter, thinking that it was the only function in the function, but it wasn't. A lot of you may not know this, but Math.sin is a function. I looked back into my Actionscript 3.0 book and saw the function Math.sin(a). I did something crazy like...

function FindSin(Fin:Number):Number {
    var Truest1:Number = Fin * Math.sin(a);
    return Truest1;
}
trace(FindSin(115));

... and got a nice error. Eventually, I realized that the parameter in the parenthesis carries the number which will be multiplied by the Sine function.

function FindSin(Fin:Number):Number {
    var Truest1:Number =  Math.sin(15);
    return Truest1;
}
trace(FindSin(115));

VICTORY


Actionscript is highly dynamic and powerful!

No comments:

Post a Comment