--------------------------------------------------------------------------------------------------------------
AS3 CODE:
--------------------------------------------------------------------------------------------------------------
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
var _currentNumber:Number = 0;
var _lastNumber:Number = 0;
var _currentFunction:int = 0;
var _lastFunctionNumber:Number = 0;
var _lastEqual:Boolean = false;
var _period:Boolean = false;
var MULTIPLY:int = 1;
var DIVIDE:int = 2;
var ADD:int = 3;
var SUBTRACT:int = 4;
var POWER:int = 5;
var SQUARE:int = 6;
var FRACTION:int = 7;
var PERCENT:int = 8;
num_0_btn.addEventListener(MouseEvent.MOUSE_DOWN,Num0Click);
function Num0Click(event:MouseEvent):void{
NumClick(0);
return;
}
num_1_btn.addEventListener(MouseEvent.MOUSE_DOWN,Num1Click);
function Num1Click(event:MouseEvent):void{
NumClick(1);
return;
}
num_2_btn.addEventListener(MouseEvent.MOUSE_DOWN, Num2Click);
function Num2Click(event:MouseEvent):void{
NumClick(2);
return;
}
num_3_btn.addEventListener(MouseEvent.MOUSE_DOWN,Num3Click);
function Num3Click(event:MouseEvent):void{
NumClick(3);
return;
}
num_4_btn.addEventListener(MouseEvent.MOUSE_DOWN,Num4Click);
function Num4Click(event:MouseEvent) : void{
NumClick(4);
return;
}
num_5_btn.addEventListener(MouseEvent.MOUSE_DOWN,Num5Click);
function Num5Click(event:MouseEvent):void{
NumClick(5);
return;
}
num_6_btn.addEventListener(MouseEvent.MOUSE_DOWN,Num6Click);
function Num6Click(event:MouseEvent):void{
NumClick(6);
return;
}
num_7_btn.addEventListener(MouseEvent.MOUSE_DOWN,Num7Click);
function Num7Click(event:MouseEvent):void{
NumClick(7);
return;
}
num_8_btn.addEventListener(MouseEvent.MOUSE_DOWN,Num8Click);
function Num8Click(event:MouseEvent):void{
NumClick(8);
return;
}
num_9_btn.addEventListener(MouseEvent.MOUSE_DOWN,Num9Click);
function Num9Click(event:MouseEvent):void{
NumClick(9);
return;
}
back_btn.addEventListener(MouseEvent.MOUSE_DOWN, BackClick);
function BackClick(event:MouseEvent): void{
var _loc_2:* = CurrentNumber.toString();
_loc_2 = _loc_2.slice(0, (_loc_2.length - 1));
CurrentNumber = Number(_loc_2);
var _loc_3:* = Math.floor(CurrentNumber);
if (CurrentNumber == _loc_3){
this._period = false;
}
else{
this._period = true;
}
return;
}
percent_btn.addEventListener(MouseEvent.MOUSE_DOWN, PercentClick);
function PercentClick(event:MouseEvent):void{
if (_lastEqual == true){
_currentFunction = PERCENT;
this._lastNumber = this.CurrentNumber;
this._currentNumber = 0;
_lastEqual = false;
return;
}
_lastEqual = false;
EqualClick(event);
_lastEqual = false;
_currentFunction = PERCENT;
this._lastNumber = this.CurrentNumber;
this._currentNumber = 0;
return;
}
multiply_btn.addEventListener(MouseEvent.MOUSE_DOWN, MultiplyClick);
function MultiplyClick(event:MouseEvent) : void{
if (_lastEqual == true){
_currentFunction = MULTIPLY;
this._lastNumber = this.CurrentNumber;
this._currentNumber = 0;
_lastEqual = false;
return;
}
_lastEqual = false;
EqualClick(event);
_lastEqual = false;
_currentFunction = MULTIPLY;
this._lastNumber = this.CurrentNumber;
this._currentNumber = 0;
return;
}
subtract_btn.addEventListener(MouseEvent.MOUSE_DOWN, SubtractClick);
function SubtractClick(event:MouseEvent): void{
if (_lastEqual == true){
_currentFunction = SUBTRACT;
_lastNumber = _currentNumber;
this._currentNumber = 0;
_lastEqual = false;
return;
}
_lastEqual = false;
EqualClick(event);
_lastEqual = false;
_currentFunction = SUBTRACT;
this._lastNumber = this.CurrentNumber;
this._currentNumber = 0;
return;
}
addition_btn.addEventListener(MouseEvent.MOUSE_DOWN, AdditionClick);
function AdditionClick(event:MouseEvent): void{
if (_lastEqual == true){
_currentFunction = ADD;
this._lastNumber = this.CurrentNumber;
this._currentNumber = 0;
_lastEqual = false;
return;
}
_lastEqual = false;
EqualClick(event);
_lastEqual = false;
_currentFunction = ADD;
this._lastNumber = this.CurrentNumber;
this._currentNumber = 0;
trace("Add _lastEqual=" + _lastEqual);
return;
}
equal_btn.addEventListener(MouseEvent.MOUSE_DOWN, EqualClick);
function EqualClick(event:MouseEvent): void{
var _loc_3:Number = NaN;
if (_currentFunction == SQUARE){
return;
}
_period = false;
if (_lastEqual == true){
_loc_3 = _currentNumber;
if (_currentFunction == ADD){
this.CurrentNumber = this._lastNumber + this._currentNumber;
}
else if (_currentFunction == SUBTRACT){
this.CurrentNumber = this._currentNumber - this._lastNumber;
}
else if (_currentFunction == MULTIPLY){
this.CurrentNumber = this._lastNumber * this._currentNumber;
}
else if (_currentFunction == DIVIDE){
this.CurrentNumber = this._currentNumber / _lastNumber;
}
else if (_currentFunction == PERCENT){
}
else if (_currentFunction == POWER){
this.CurrentNumber = Math.pow(_currentNumber, _lastNumber);
}
return;
}
_lastEqual = true;
var _loc_2:* = _currentNumber;
if (_currentFunction == ADD)
{
this.CurrentNumber = this._lastNumber + this._currentNumber;
}
else if (_currentFunction == SUBTRACT){
this.CurrentNumber = this._lastNumber - this._currentNumber;
}
else if (_currentFunction == MULTIPLY){
this.CurrentNumber = this._lastNumber * this._currentNumber;
}
else if (_currentFunction == DIVIDE){
trace("_lastNumber / this._currentNumber " + _lastNumber + " / " + _currentNumber);
this.CurrentNumber = this._lastNumber / this._currentNumber;
}
else if (_currentFunction == PERCENT){
this.CurrentNumber = this._lastNumber / this._currentNumber * 100;
}
else if (_currentFunction == POWER)
{
this.CurrentNumber = Math.pow(_lastNumber, _currentNumber);
}
_lastNumber = _loc_2;
return;
}
period_btn.addEventListener(MouseEvent.MOUSE_DOWN, PeriodClick);
function PeriodClick(event:MouseEvent): void{
_period = true;
output_window_txt.appendText(".");
return;
}
ce_btn.addEventListener(MouseEvent.MOUSE_DOWN, CEClick);
function CEClick(event:MouseEvent): void{
CurrentNumber = 0;
return;
}
c_btn.addEventListener(MouseEvent.MOUSE_DOWN, CClick);
function CClick(event:MouseEvent) : void{
this.CurrentNumber = 0;
this._lastFunctionNumber = 0;
this._lastNumber = 0;
_currentFunction = 0;
_lastEqual = false;
_period = false;
return;
}
calculator_btn.addEventListener(MouseEvent.MOUSE_DOWN,CalculatorClick);
function CalculatorClick(event:MouseEvent): void{
var _loc_2:String = "http://www.embedcalculators.com";
var _loc_3:* = new URLRequest(_loc_2);
navigateToURL(_loc_3, "_new");
return;
}
sqrt_btn.addEventListener(MouseEvent.MOUSE_DOWN, SqrtClick);
function SqrtClick(event:MouseEvent): void{
this.CurrentNumber = Math.sqrt(this.CurrentNumber);
return;
}
plus_minus_btn.addEventListener(MouseEvent.MOUSE_DOWN, PlusMinusClick);
function PlusMinusClick(event:MouseEvent): void{
this.CurrentNumber = -CurrentNumber;
return;
}
divide_btn.addEventListener(MouseEvent.MOUSE_DOWN,DivideClick);
function DivideClick(event:MouseEvent): void{
trace("DivideClick");
if (_lastEqual == true){
trace("last equal");
_currentFunction = DIVIDE;
this._lastNumber = this.CurrentNumber;
this._currentNumber = 0;
_lastEqual = false;
return;
}
_lastEqual = false;
EqualClick(event);
_lastEqual = false;
_currentFunction = DIVIDE;
this._lastNumber = this.CurrentNumber;
trace("_lastNumber=" + _lastNumber);
this._currentNumber = 0;
return;
}
function FractionClick(event:MouseEvent): void{
if (_lastEqual == true){
CurrentNumber = 1 / CurrentNumber;
_lastEqual = false;
return;
}
_lastEqual = false;
EqualClick(event);
_lastEqual = false;
CurrentNumber = 1 / CurrentNumber;
return;
}
function PowerClick(event:MouseEvent): void{
if (_lastEqual == true){
_currentFunction = POWER;
this._lastNumber = this.CurrentNumber;
this._currentNumber = 0;
_lastEqual = false;
return;
}
_lastEqual = false;
EqualClick(event);
_lastEqual = false;
_currentFunction = POWER;
this._lastNumber = this.CurrentNumber;
this._currentNumber = 0;
return;
}
function SquareClick(event:MouseEvent) : void{
var _loc_2:* = CurrentNumber;
this.CurrentNumber = Math.pow(this.CurrentNumber, 2);
return;
}
function NumClick(param1:int) : void{
if (this._period == false){
CurrentNumber = CurrentNumber * 10;
CurrentNumber = CurrentNumber + param1;
}
else{
output_window_txt.appendText(param1.toString());
this._currentNumber = Number(output_window_txt.text);
}
return;
}
function set CurrentNumber(param1:Number): void{
_currentNumber = param1;
output_window_txt.text = String(_currentNumber);
return;
}
function get CurrentNumber():Number{
return _currentNumber;
}
function set SaveNumber(param1:Number):void{
_saveNumber = param1;
return;
}
function get SaveNumber() : Number{
return _saveNumber;
}
EmoticonEmoticon