How to create simple Calculator in Flash ( Actionscript 3 )

Create buttons and text fields as created above. give them instance name and change its type. Write down this code in action panel . And run it ( Crlt  + Enter ).  as mentioned in picture.

Explanation of code:

// so that user can only type numbers in text box.

cal.addEventListener(MouseEvent.CLICK, result_);
// Action to button. (cal is our button)
//result_ is our function , in simple words action to button.

function result_(e:Event){
//Introduced new variable ( r ) , num1 + num2 means addition of two numbers,  here first we have converted text into numbers ( uint ),  then converted to text again ( String ).var r:String=String(uint(num1.text)+uint(num2.text));

// Inserted ( r = result), r into textfeild (re ).

// end of function. } ============================================================================================ This simplest Tutorial, after following this , if you have doubts , can ask me. ============================================================================================ This is calculator create by me. In photoshop and Flash. After working in actionscript you can also create your own graphic. And add it to button layer.


Get Biggest Number in Array ( Actionscript 3 )

//get biggest number…………

// define array and number
var avg:Array=new Array(1,5,8,9, 43,56,88,54,67,90,66,45);

// define where big number holder

var bigno:uint=0;

// define result
var res:uint;

// for loop repeat action
for(var i:uint=0; i<avg.length; i++){

// condition if 0 is less than avg[i], then bigno  equal to avg[i]
if(  bigno<avg[i] ){


//finally trace results

Average in Actionscript 3

// define array
var avg:Array=new Array(13,24,35,46,21,34,78,96,56,78,90,65,43);

// define bigno to hold biggest number
var bigno:uint=0;

// define a variable to hold sum of array
var res:uint;

//for loop to repeat actions and get sum of array.
for(var i:uint=0; i<avg.length; i++){

//condition for bigno, if bigno is smaller than number in array.
if(bigno<avg[i] || bigno>0){

// res for result of sum of total numbers in array.


//trace sum of array

// to know actual length of  array
trace(“length of arr”+avg.length);

// to know the final result, res= length of array.
trace(“result is  “+res/avg.length);


//you should get the following result

legth of arr13
result is  52.23076923076923