PDA

View Full Version : class / method help


CEinNYC
02-27-2011, 03:25 AM
Hey, AS3 newbie...

First my code, then my question


package
{
import flash.utils.Timer;



public class MathHelper

{
public function addNumbers (firstNumber: Number, secondNumber:Number) : void
{
var result:Number = firstNumber + secondNumber;
trace (firstNumber " + " secondNumber "=" + result);
}


public function SOMETHING WITH AN ARRAY? : void
{
var my_array:Array = new Array( 100, 75, 50, 25 ); //syntax for the array with numbers
var average:Number = 0; //stores the sum of the array

for(i=0; my_array.length;i++) // adds the numbers of the array
{
average +=my_array[i];
}

if(i+1 == my_array.length) //stops the addition once the length of the array has been reached
{
var totalAverage:Number = average / my_array.length; //the math
trace (totalAverage);
}
}

public function methodCalledCount(e:Timer:Event):void
{
trace ("addNumbers has been run: " +e.addNumbers;);
trace ("SOMETHING WITH AN ARRAY has been run: " +e.SOMETHING WITH AN ARRAY);

}


}



}



addNumbers(firstNumber, secondNumber); //WHERE DOES THIS GO?
SOMETHING TO START ARRAY //WHERE DOES THIS GO?




My first function, "addNumbers" needs to add two numbers and trace the results.

My second function, "SOMETHING WITH AN ARRAY? : void" ;) I'm uncertain of the syntax to call a function with an array. Lots of examples online, all performed differently.. None yet performed correctly.

Lastly, I need to trace the number of times this class is called, (ran/compiled, etc).

Thanks for any advice!

CEinNYC
02-27-2011, 05:04 PM
To bump this up...

Can I call two functions in the same external class file? Or do I need a third .as file to call these functions? We are not to call this from the main .fla timeline.