Errata

 

Hangman Unstrung

Good Catch Timothy!

lettersGuessed needs to be reset to play reliably.

Here's the wrong version again:

//Movie setup

// Initialize array of words

wordList = ["aaaaaaa", "x"];

// Initialize an empty array to store letters from our mystery word from wordList

lettersNeeded = new Array(10);

//Initialize an empty array to store the letters guessed through the input_txt field

lettersGuessed = new Array(10);

 

To correct, move to the playGame_btn callback before the loop that fills the array:

//Moved from movie setup: Initialize an empty array to

//store the letters guessed through the input_txt field

lettersGuessed = new Array(10);

//Fill the lettersGuessed array with the same number of questionmarks

//as there are letters in selectedWord.

for(counter=0;
counter<selectedWord.length;
counter++) {

lettersGuessed[counter] = "?";

}

Picking Up Where We Left Off...

 

The Math Object

Source

 

Syntax

Math.someMethod(); //returns someValue

Top math methods

Math.abs(someNumber);

Computes an absolute value. -123 become 123. Handy if you're not sure which number is going to be larger when you subtracting one from another.

 

Math.floor(someNumber);

Converts a floating point number (1.234) to an integer (1,2,3) by rounding its decimal values down to zero. Similar to Math.ceil(someNumber) and Math.round(someNumber)

myNumber = 1.5;

trace(Math.floor(myNumber));

Yields:

1

In other words, it strips off any decimal places.

 

Math.max(firstNumber, secondNumber);

Returns the larger of the two numbers. Useful for Math.random() method.

 

Math.min(firstNumber, secondNumber);

Returns the smaller of the two numbers. Useful for Math.random() method.

 

Math.random();

Returns a pseudo-random many digit number between 0.0 and 1.0.

For example: 0.365308396052569 (number of digits vary by OS and CPU)

So , to get a usable integer you multiply the result by 10, 100, 1000 etc. to get numbers from 0 to 9, 0 to 99, 0 to 999 etc.

trace( Math.random()*100);

Then strip off the excess decimal places with .floor()

trace(Math.floor( (Math.random()*100));

returns a random number between 0 and 99

 

But what about a range of numbers? Like 3 to 54.

minVal = 3;

maxVal = 54;

//get a random number

ranNum = Math.random();

trace("ranNum is: " + ranNum);

//multiply the random number by distance

//between the maximum and minimum values,

//then chop off the decimals

wholeNum = Math.floor(ranNum*(maxVal + 1 - minVal));

trace("wholeNum is: " + wholeNum);

//Boost the number up by the minimum

rangeNum = minVal + wholeNum;

trace("rangeNum is: " + rangeNum);

 

Get A Random Number Function

In a function:

getRandom =
function(minVal,maxVal) {

return minVal + Math.floor( Math.random() * (maxVal + 1 - minVal));

}

trace("The random number is: " + getRandom(3,54));

Other methods

Don't forget the parentheses
( )

Trigonometry

Math.acos(someNumber);

Computes an arc cosine.

Math.asin(someNumber);

Computes an arc sine.

Math.atan(someNumber);

Computes an arc tangent.

Math.atan2(someNumber, somePoint);

Computes an angle from the x-axis to the point.

Math.cos(someNumber);

Computes a cosine.

Math.sin(someNumber);

Computes a sine.

Math.tan(someNumber);

Computes a tangent.

 

Rounding off

Math.ceil(someNumber);

Rounds a number up to the nearest integer.

Math.round(someNumber);

Rounds to the nearest integer.

 

Misc. functions

Math.exp(someNumber);

Computes an exponential value.

Math.log(someNumber);

Computes a natural logarithm.

Math.pow(someNumber,somePower);

Computes x raised to the power of the y.

Math.sqrt(someNumber);

Computes a square root.

Properties

In CAPS

Math.E

Euler's constant and the base of natural logarithms (approximately 2.718).

Math.LN2

The natural logarithm of 2 (approximately 0.693).

Math.LOG2E

The base 2 logarithm of e (approximately 1.442).

Math.LN10

The natural logarithm of 10 (approximately 2.302).

Math.LOG10E

The base 10 logarithm of e (approximately 0.434).

Math.PI

The ratio of the circumference of a circle to its diameter (approximately 3.14159).

Math.SQRT1_2

The reciprocal of the square root of 1/2 (approximately 0.707).

Math.SQRT2

The square root of 2 (approximately 1.414).

The Color Object

Source

 

Counter-Intelligence

You can't set the tint of a movieClip directly. Counter-intuitively, there is no:

myClip_mc._tint

even though there's a:

myClip_mc._alpha.

You Need The Color Object

You must create the color object and give it a movieClip target.

myClipColor = new color(myClip_mc);

 

Get the color of the movieclip

myClipColor.getRGB()

 

Set the color of the movieClip

You should use a hexadecimal number, which actionScript recognizes when it's preceded by "0x" at the beginning.

myClipColor.setRGB(0xNNNNNN)

Weirdness:

Get and Set Transform

"Transform" in actionScript is "Advanced" in the property inspector.

 

Get the transform of the movieClip

myClipColor.getTransform(). whichTransformValue

 

Set the transform of the movieClip

myClipColor.setTransform(myColorTransform);

 

But it needs an object with predetermined values set:

myColorTransform = new Object();

myColorTransform.ra = 50;

myColorTransform.rb = 244;

myColorTransform.ga = 40;

myColorTransform.gb = 112;

myColorTransform.ba = 12;

myColorTransform.bb = 90;

myColorTransform.aa = 40;

myColorTransform.ab = 70;

Other Built-in Objects

Details in class 10

Boolean
Date
Function
Number
String
Key
Mouse
MovieClip
Selection
Sound
Stage
System
TextField
TextFormat