Tuesday, 3 May 2016

AS3 CALCUALTORS


---------------------------------------------------------------------------------------------------------------
COPY AND PASTE IMAGE ON STAGE AND MAKE ON THIS IMAGE
 LESS ALPHA BUTTON AND MAKE COPIES OF THIS BUTTON
https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=as3+calculator&start=10
http://www.embedcalculators.com/
<object type="application/x-shockwave-flash" data="http://www.embed.com/flash/StandardCalculator.swf" width="350" height="430">
http://sonusharmadelhi.blogspot.co.uk/2010/09/calculator.html
https://88fbbe62324103b6816f807f8bf4f2b767f4f12c.googledrive.com/host/0BzTF4maHDSaGZHlYdVEwanloQzA/calculadora01.swf
https://88fbbe62324103b6816f807f8bf4f2b767f4f12c.googledrive.com/host/0BzTF4maHDSaGZHlYdVEwanloQzA/calculadora02.swf
https://88fbbe62324103b6816f807f8bf4f2b767f4f12c.googledrive.com/host/0BzTF4maHDSaGZHlYdVEwanloQzA/calculadora03.swf
https://88fbbe62324103b6816f807f8bf4f2b767f4f12c.googledrive.com/host/0BzTF4maHDSaGZHlYdVEwanloQzA/calculadora04.swf
https://88fbbe62324103b6816f807f8bf4f2b767f4f12c.googledrive.com/host/0BzTF4maHDSaGZHlYdVEwanloQzA/calculadora05.swf

---------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
1)USE BLUE CALCULATOR IMAGE
2) MAKE INDIVISIBLE BUTTON WITH ALPHA SETTING 11
3) NOW MAKE COPIES THIS INDIVISIBLE BUTTON WITH ALPHA SETTING 11
CLASS AS3 CODE
-------------------------------------------------------------------------------------------------
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class calculator extends MovieClip{
private var numbers:Array;
private var operators:Array;
private var op:String;
private var num1:Number;
private var num2:Number;
public function calculator(){
numbers = [num0_btn,num1_btn,num2_btn,num3_btn,num4_btn,
num5_btn,num6_btn,num7_btn,num8_btn,num9_btn];
operators = [divide_btn,multiply_btn,add_btn,substract_btn,equal_btn];
addListeners();
}
private function addListeners():void{
for (var i:uint=0; i<numbers.length; i++){
numbers[i].addEventListener(MouseEvent.CLICK, pressNumber);
}
for (i =0; i<operators.length; i++){
operators[i].addEventListener(MouseEvent.CLICK, pressOperator);
}
clear_btn.addEventListener(MouseEvent.CLICK, clearAll);
dot_btn.addEventListener(MouseEvent.CLICK, addDot);
}
private function pressNumber(event:MouseEvent):void{
var instanceName:String = event.target.name;
var namePushed:String = instanceName.charAt(3);
if (scr_txt.text == "0" || num1 == Number(scr_txt.text)){
scr_txt.text = "";
}
scr_txt.appendText(namePushed);
}
private function pressOperator(event:MouseEvent):void{
var instanceName:String = event.target.name;
var currentOp:String = instanceName.slice(0,instanceName.indexOf("_"));
if (! num1){
num1 = Number(scr_txt.text);
scr_txt.text = "";
op = currentOp;
}
else if (!num2){
num2 = Number(scr_txt.text);
showCal();
op = currentOp;
}
}
private function clearAll(event:MouseEvent):void{
scr_txt.text = "0";
num1 = num2 = NaN;
}
private function addDot(event:MouseEvent):void{
if (num1 == Number(scr_txt.text)){
scr_txt.text = "0";
}
if (scr_txt.text.indexOf(".") == -1){
scr_txt.appendText(".");
}
}
private function showCal():void{
switch (op)
{
case "divide" :
num1 /= num2;
break;
case "multiply" :
num1*=num2;
break;
case "add" :
num1+=num2;
break;
case "substract" :
num1-=num2;
break;
default :
break;
}
scr_txt.text=String(num1);
num2=NaN;
}
}
}
-------------------------------------------------------------------------------------------------
OR USE WITHOUT CLASS AS3 CODE
-------------------------------------------------------------------------------------------------
var numbers:Array;
var operators:Array;
var op:String;
var num1:Number;
var num2:Number;
numbers =[num0_btn,num1_btn,num2_btn,num3_btn,num4_btn,
num5_btn,num6_btn,num7_btn,num8_btn,num9_btn];
operators =[divide_btn,multiply_btn,add_btn,substract_btn,equal_btn];
for (var i:uint=0; i<numbers.length; i++){
numbers[i].addEventListener(MouseEvent.CLICK, pressNumber);
}
for (i =0; i<operators.length; i++){
operators[i].addEventListener(MouseEvent.CLICK, pressOperator);
}
clear_btn.addEventListener(MouseEvent.CLICK, clearAll);
dot_btn.addEventListener(MouseEvent.CLICK, addDot);
function pressNumber(event:MouseEvent):void{
var instanceName:String = event.target.name;
var namePushed:String = instanceName.charAt(3);
if (scr_txt.text == "0" || num1 == Number(scr_txt.text)){
scr_txt.text = "";
}
scr_txt.appendText(namePushed);
}
function pressOperator(event:MouseEvent):void{
var instanceName:String = event.target.name;
var currentOp:String = instanceName.slice(0,instanceName.indexOf("_"));
if (! num1){
num1 = Number(scr_txt.text);
scr_txt.text = "";
op = currentOp;
}
else if (!num2){
num2 = Number(scr_txt.text);
showCal();
op = currentOp;
}}
function clearAll(event:MouseEvent):void{
scr_txt.text = "0";
num1 = num2 = NaN;
}
function addDot(event:MouseEvent):void
{
if (num1 == Number(scr_txt.text))
{
scr_txt.text = "0";
}
if (scr_txt.text.indexOf(".") == -1)
{
scr_txt.appendText(".");
}
}
function showCal():void
{
switch (op)
{
case "divide" :
num1 /= num2;
break;
case "multiply" :
num1*=num2;
break;
case "add" :
num1+=num2;
break;
case "substract" :
num1-=num2;
break;
default :
break;
}
scr_txt.text=String(num1);
num2=NaN;
}














EmoticonEmoticon