--------------------------------------------------------------------------------------------------------------------------
SCIENTIFIC CALCULATOR AS2
http://carremaths.yellis.net/321-fr-207.swf
http://www.flashkit.com/movies/Scripting/Maths/Ultimate-Gustavo_-9012/index.php
--------------------------------------------------------------------------------------------------------------------------
//ACTION LAYER CODE:
function decode(chaine){
var _loc7 = false;
if (chaine.indexOf("{") != -1){
var _loc3 = chaine.split("{");
var _loc4 = -1;
_loc7 = true;
}
else if (chaine.indexOf("}") != -1){
_loc3 = chaine.split("}");
_loc4 = 1;
_loc7 = true;
}
if (_loc7){
var _loc6 = Number(_loc3[0]);
var _loc5 = Number(_loc3[1]);
var _loc2 = _loc6 * Math.pow(10, _loc4 * _loc5);
return (_loc2);
}
else if (chaine == "INFINITY"){
return (Infinity);
}
else if (chaine == "-INFINITY"){
_loc2 = -Infinity;
}
else
{
_loc2 = Number(chaine);
}
if (debug){
}
return (_loc2);
}
function encode(nombre){
var _loc2 = String(nombre);
var _loc8 = false;
if (_loc2.indexOf("e") != -1){
var _loc4 = _loc2.split("e");
var _loc6 = Number(_loc4[0]);
var _loc3 = Number(_loc4[1]);
if (_loc3 > 0)
{
var _loc5 = "}";
}
else
{
_loc5 = "{";
}
var _loc1 = _loc6 + _loc5 + Math.abs(_loc3);
}
else{
_loc1 = CalcUtils.replace(_loc2, "Infinity", "INFINITY");
}
if (debug){
}
return (_loc1);
}
function calculSimple(operateur, n1, n2){
n1 = CalcUtils.replace(n1, "m", "-");
var _loc2;
if (debug){
}
if (String(n1) == "NaN"){
n1 = 0;
}
if (String(n2) == "NaN"){
n2 = 0;
}
n1 = decode(n1);
n2 = decode(n2);
if (debug){
}
switch (operateur){
case "+":{
_loc2 = n1 + n2;
break;
}
case "-":{
_loc2 = n1 - n2;
break;
}
case "*":{
_loc2 = n1 * n2;
break;
}
case "/":{
_loc2 = n1 / n2;
break;
}
case "^":{
_loc2 = Math.pow(n1, n2);
break;
}
case "%":{
_loc2 = n1 % n2;
break;
}
case "c":{
if (deg){
_loc2 = Math.cos(n2 / 5.729578E+001);
}
else{
_loc2 = Math.cos(n2);
}
break;
}
case "C":{
if (deg){
_loc2 = 5.729578E+001 * Math.acos(n2);
}
else{
_loc2 = Math.acos(n2);
}
break;
}
case "s":{
if (deg){
_loc2 = Math.sin(n2 / 5.729578E+001);
}
else{
_loc2 = Math.sin(n2);
}
break;
}
case "S":{
if (deg){
_loc2 = 5.729578E+001 * Math.asin(n2);
}
else
{
_loc2 = Math.asin(n2);
}
break;
}
case "t":{
if (deg){
_loc2 = Math.tan(n2 / 5.729578E+001);
}
else{
_loc2 = Math.tan(n2);
}
break;
}
case "T":{
if (deg){
_loc2 = 5.729578E+001 * Math.atan(n2);
}
else{
_loc2 = Math.atan(n2);
}
break;
}
case "a":{
_loc2 = Math.abs(n2);
break;
}
case "!":{
if (n1 < 0 || Math.round(n1) != n1){
temp = Number.NaN;
}
else if (n1 == 0){
temp = 1;
}
else{
var temp = n1;
for (i = 2; i < n1; i++){
temp = temp * i;
}
}
_loc2 = temp;
break;
}
case "v":{
_loc2 = Math.sqrt(n2);
break;
}
case "l":{
_loc2 = Math.log(n2);
break;
}
case "L":{
_loc2 = Math.log(n2) / 2.302585E+000;
break;
}
case "e":{
_loc2 = Math.exp(n2);
break;
}
}
_loc2 = encode(_loc2);
return (_loc2);
}
function tablify(chaine){
if (debug){
}
var _loc3 = "";
var _loc2 = new Array();
for (var _loc1 = 0; _loc1 < chaine.length; ++_loc1){
car = chaine.charAt(_loc1);
if (!CalcUtils.in_array(tabOperateurs0,car) && !CalcUtils.in_array(tabOperateurs1,car)
&& !CalcUtils.in_array(tabOperateurs2,car)){
_loc3 = _loc3 + car;
continue;
}
_loc2.push(_loc3);
_loc3 = "";
_loc2.push(car);
}
_loc2.push(_loc3);
for (var _loc1 = 0; _loc1 < _loc2.length; ++_loc1){
if (_loc2[_loc1] == "")
{
var _loc4 = _loc2[_loc1 + 1] + _loc2[_loc1 + 2];
_loc2.splice(_loc1, 3, _loc4);
}
}
return (_loc2);
}
function handleOpLevel(tabTablified, opTab){
if (debug){
}
while (CalcUtils.has_any_of(tabTablified, opTab)){
for (var _loc1 = 0; _loc1 < tabTablified.length; ++_loc1)
{
var _loc5 = String(tabTablified[_loc1]);
if (CalcUtils.in_array(opTab, _loc5)){
var _loc3 = _loc1;
op = tabTablified[_loc1];
operande1 = tabTablified[_loc3 - 1];
operande2 = tabTablified[_loc3 + 1];
var _loc4 = calculSimple(op, operande1, operande2);
if (debug){
}
if (op == "!" && (tabTablified[_loc3 - 2] == "-" || Math.round(operande1) != operande1))
{
thereHasBeenAProblem = true;
} // end if
tabTablified.splice(_loc3 - 1, 3, _loc4);
_loc1 = 0;
}
}
}
return (tabTablified);
}
function handleTablified(tablified){
if (debug){
}
var _loc1 = handleOpLevel(tablified, tabOperateurs0);
_loc1 = handleOpLevel(_loc1, tabOperateurs1);
_loc1 = handleOpLevel(_loc1, tabOperateurs2);
return (_loc1);
}
function checkBrackets(ch)
{
if (debug)
{
} // end if
var _loc2 = 0;
var _loc4 = false;
for (var _loc1 = 0; _loc1 < ch.length; ++_loc1)
{
car = ch.charAt(_loc1);
if (car == "(")
{
++_loc2;
}
else if (car == ")")
{
--_loc2;
}
if (_loc2 < 0)
{
_loc4 = true;
}
}
return (_loc2 == 0 && !_loc4);
}
function resolve(laChaine){
if (debug){
}
var _loc1 = tablify(laChaine);
_loc1 = handleTablified(_loc1);
return (_loc1);
} // End of the function
function cleanString(chaine)
{
if (debug)
{
} // end if
var _loc1 = chaine;
_loc1 = CalcUtils.replace(_loc1, " ", "");
_loc1 = CalcUtils.replace(_loc1, "+-", "-");
_loc1 = CalcUtils.replace(_loc1, "-+", "-");
_loc1 = CalcUtils.replace(_loc1, "--", "+");
_loc1 = CalcUtils.replace(_loc1, "p", String(3.141593E+000));
_loc1 = CalcUtils.replace(_loc1, "acos", "_C");
_loc1 = CalcUtils.replace(_loc1, "cos", "_c");
_loc1 = CalcUtils.replace(_loc1, "asin", "_S");
_loc1 = CalcUtils.replace(_loc1, "sin", "_s");
_loc1 = CalcUtils.replace(_loc1, "atan", "_T");
_loc1 = CalcUtils.replace(_loc1, "tan", "_t");
_loc1 = CalcUtils.replace(_loc1, "ln", "_l");
_loc1 = CalcUtils.replace(_loc1, "log", "_L");
_loc1 = CalcUtils.replace(_loc1, "!", "!_");
_loc1 = CalcUtils.replace(_loc1, "abs", "_a");
_loc1 = CalcUtils.replace(_loc1, "v", "_v");
_loc1 = CalcUtils.replace(_loc1, "Infinity", "INFINITY");
_loc1 = CalcUtils.replace(_loc1, "e", "_e");
_loc1 = CalcUtils.replace(_loc1, "__", "_");
if (_loc1.charAt(0) == "-")
{
_loc1 = "m" + _loc1.substr(1);
}
return (_loc1);
}
function handleBrackets(laChaine){
if (debug){
}
while (laChaine.indexOf("(") != -1){
if (debug){
}
var _loc4 = 0;
var _loc3 = 0;
for (var _loc1 = 0; _loc3 == 0; ++_loc1){
if (laChaine.charAt(_loc1) == "("){
_loc4 = _loc1;
continue;
}
if (laChaine.charAt(_loc1) == ")"){
_loc3 = _loc1;
}
}
var _loc5 = laChaine.substring(_loc4, _loc3 + 1);
_loc5 = _loc5.slice(1, -1);
apresCalcul = resolve(_loc5);
aGauche = laChaine.substring(0, _loc4);
aDroite = laChaine.substring(_loc3 + 1);
laChaine = cleanString(aGauche + apresCalcul + aDroite);
}
return (resolve(laChaine));
}
function checkPI(str){
var _loc2 = str.split("p");
for (var _loc1 = 0; _loc1 < _loc2.length - 1; ++_loc1){
if (!isNaN(_loc2[_loc1].charAt(_loc2[_loc1].length - 1))){
_loc2[_loc1] = _loc2[_loc1] + "*";
}
}
str = _loc2.join("p");
return (str);
}
function calculComplexe(bigString){
thereHasBeenAProblem = false;
if (deg == undefined){
deg = false;
}
if (debug){
}
if (checkBrackets(bigString)){
bigString = checkPI(bigString);
bigString = cleanString(bigString);
var _loc2 = handleBrackets(bigString);
if (String(_loc2) == "NaN"){
return (false);
}
else{
if (debug){
}
return (thereHasBeenAProblem ? (false) : (decode(_loc2.toString())));
}
}
else
{
return (false);
}
}
function initialize(){
aff.htmlText = "";
brackets.gotoAndStop(1);
enCours = "";
avant = "";
stockEnCours = "";
justResolved = false;
changeShift(false);
formatParentheses = true;
tabLongueurs = new Array();
deg = false;
ans = "";
}
function cleanRes(res){
return (String(res).indexOf("e") != -1 && String(res) != "false" ? ("(" + CalcUtils.replace(String(res), "e+", "*10^") + ")") : (res));
}
function addSomething(quoi, op){
if (justResolved && op && String(res) != "false"){
enCours = enCours + cleanRes(res);
}
else if (quoi == "."){
var _loc1 = enCours.split("-");
_loc1 = _loc1[_loc1.length - 1].split("+");
_loc1 = _loc1[_loc1.length - 1].split("/");
_loc1 = _loc1[_loc1.length - 1].split("*");
if (_loc1[_loc1.length - 1].indexOf(".") != -1)
{
quoi = "";
}
}
enCours = enCours + quoi;
tabLongueurs.push(String(quoi).length);
stockEnCours = "<p align=\'left\'>" + enCours + "</p>";
justResolved = false;
updateScreen();
} // End of the function
function addSomethingAns(avant, apres, sinon)
{
if (enCours == "" && ans != "")
{
addSomething(avant + ans + apres);
}
else if (enCours != "")
{
addSomething(sinon);
}
}
function toucheC(){
enCours = "";
updateScreen();
}
function goBack(){
enCours = enCours.slice(0, -tabLongueurs.pop());
stockEnCours = "<p align=\'left\'>" + enCours + "</p>";
updateScreen();
}
function resolveCalc()
{
if (enCours != ""){
var _loc1 = CalcUtils.replace(enCours, "exp(", "e(");
res = calculComplexe(_loc1);
avant = avant + (stockEnCours + "<p align=\'right\'>" + res + "</p>");
enCours = "";
justResolved = true;
ans = cleanRes(res);
System.setClipboard(res);
updateScreen();
}
}
function changeShift(bool){
shift = bool;
shifted.gotoAndStop(bool ? (2) : (1));
}
function updateScreen(){
formatParentheses = checkBrackets(enCours);
brackets.gotoAndStop(formatParentheses ? (1) : (2));
aff.htmlText = avant + "<p align=\'left\'>" + enCours + "</p>";
aff.scroll = aff.maxscroll;
}
var tabOperateurs0 = new Array("c", "C", "s", "S", "t", "T", "l", "L", "!", "a", "v", "e", "^");
var tabOperateurs1 = new Array("*", "/", "%");
var tabOperateurs2 = new Array("-", "+");
debug = false;
initialize();
SCIENTIFIC CALCULATOR CLASS AS2
SAVE FILE WITH AS
CalcUtils.as
--------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------
SAVE CLASS IN SAME FOLDER WHERE SAVE FLA FILE
CalcUtils.as CODE
--------------------------------------------------------------------------------------------------------------------------
class CalcUtils{
function CalcUtils(){
}
static function in_array(tablo, str){
var _loc3 = false;
for (var _loc1 = 0; _loc1 < tablo.length; ++_loc1){
if (tablo[_loc1] == str){
_loc3 = true;
}
}
return (_loc3);
}
static function first_pos(tablo, str){
var _loc1 = 0;
if (!CalcUtils.in_array(tablo, str)){
return (-1);
}
else{
while (tablo[_loc1] != str){
++_loc1;
}
return (_loc1);
}
}
static function has_any_of(tablo, tabElts){
var _loc2 = false;
for (var _loc1 = 0; _loc1 < tablo.length && !_loc2; ++_loc1){
_loc2 = CalcUtils.in_array(tabElts, tablo[_loc1]);
}
return (_loc2);
}
static function replace(chaine, trouve, remplace){
return (chaine.split(trouve).join(remplace));
}
}
BUTTONS INSIDE CODE:
--------------------------------------------------------------------------------------------------------------------------
// 0 BUTTON CODE:
on(release, keyPress "0"){
if(shift){
addSomething("p");
changeShift(false);
}
else{
addSomething(0);
}
}
// DOT BUTTON CODE:
on(release,keyPress"."){
addSomething(".");
}
// BRACKET BUTTON ( CODE:
on(release,keyPress"("){
addSomething("(");
}
// BRACKET BUTTON ) CODE:
on(release,keyPress")"){
addSomething(")");
}
//EQUAL BUTTON CODE:
on(release,keyPress"<Space>"){
resolveCalc();
}
// 1 BUTTON CODE:
on(release,keyPress"1"){
addSomething(1);
}
// 2 BUTTON CODE:
on(release,keyPress"2"){
addSomething(2);
}
// 3 BUTTON CODE:
on(release,keyPress"3"){
addSomething(3);
}
//+ BUTTON CODE:
on(release,keyPress "+"){
addSomething("+", true);
}
//- BUTTON CODE:
on (release, keyPress "-"){
addSomething("-", true);
}
// 4 BUTTON CODE:
on(release,keyPress"4"){
addSomething(4);
}
// 5 BUTTON CODE:
on(release,keyPress"5"){
addSomething(5);
}
// 6 BUTTON CODE:
on(release,keyPress"6"){
addSomething(6);
}
//* MULTI BUTTON CODE:
on(release,keyPress"*"){
addSomething("*",true);
}
// / DIVIDE BUTTON CODE:
on(release,keyPress"/"){
addSomething("/",true);
}
// 7 BUTTON CODE:
on(release,keyPress"7"){
addSomething(7);
}
// 8 BUTTON CODE:
on(release,keyPress"8"){
addSomething(8);
}
// 9 BUTTON CODE:
on(release,keyPress"9"){
addSomething(9);
}
// C BUTTON CODE:
on(release,keyPress"C"){
toucheC();
}
// END BUTTON CODE:
on(release,keyPress"<End>"){
initialize();
}
// ^ POWER BUTTON CODE:
on(release,keyPress "^"){
if(shift){
addSomethingAns("", "!", "!");
changeShift(false);
}
else{
addSomethingAns("", "^", "^");
}
}
// ^ * (-1) MULTI POWER BUTTON CODE:
on(release){
if(shift){
addSomething("abs(");
changeShift(false);
}
else{
addSomethingAns("", "^(-1)", "^(-1)");
}
}
// ^ * (2) MULTI POWER BUTTON CODE:
on(release,keyPress"v"){
if(shift){
addSomething("v");
changeShift(false);
}
else{
addSomethingAns("","^2","^2");
}
}
// % PERCENTAGE BUTTON CODE:
on(release,keyPress"%"){
addSomething("%");
}
//PRESS ANSWER BUTTON AFTER EQUAL BUTTON
// % ANSWER BUTTON CODE:
on(release,keyPress"a"){
addSomething(ans);
}
//LOG BUTTON CODE:
on(release,keyPress"l"){
if(shift){
addSomething("log(");
changeShift(false);
}
else{
addSomething("ln(");
}
}
//EXP BUTTON CODE:
on(release,keyPress"e"){
addSomething("exp(");
}
// ^ * (10) MULTI POWER BUTTON CODE:
on(release){
addSomething("*10^");
}
//DELETE DIGIT ON BY ONE CODE:
on(release,keyPress"b"){
goBack();
}
//DEG BUTTON CODE:
on(release,keyPress "d"){
deg=!deg;
radDeg.gotoAndStop(deg?(2):(1));
}
//COS BUTTON CODE:
on(release,keyPress"c"){
if(shift){
addSomething("acos(");
changeShift(false);
}
else{
addSomething("cos(");
}
}
//SIN BUTTON CODE:
on(release,keyPress"s"){
if(shift){
addSomething("asin(");
changeShift(false)
}
else{
addSomething("sin(");
}
}
//TAN BUTTON CODE:
on(release,keyPress "t"){
if(shift){
addSomething("atan(");
changeShift(false);
}
else{
addSomething("tan(");
}
}
//SHIFT RAD BUTTON CODE:
on(release,keyPress "<Home>"){
changeShift(!shift);
}
EmoticonEmoticon