

<< Prev 5 |
Next 5
check if arguments is a number (work with void string)
 |
 |
function IsNum(checkthis) {
if(((Number(typeof checkthis)).toString()== "NaN")&&((Number(checkthis add "")).toString()== "NaN"))
{
trace(checkthis add " is not a number")
// isNaN?
return false
// yes
}
else
{
trace(checkthis add " is a numeric string")
// isNaN?
return true
// no
}
}
Posted by: FABIO VERGANI | website
http:\\www.kora.it
|
 |
 |
 |
CheckBox Component Application
 |
 |
// Title: Celcius to Fahrenheit (Fahrenheit to Celcius) Converter
// Level of Expertise: Intermediate (with the MX Version)
// Objective: Basic usage of checkBox component
// Author: Mustafa Basgun (mustafa@basgun.com)
// Date: 28th September 2002, Saturday
// Today, I received my original "OOP with ActionScript" book from New Riders. :)
// Create three textFields named as inputValue, result and errorMessage.
// Put the checkBox component and call it as fahrenheitCheck.
// Following code should be for the converting button:
on (release) {
result = ""
if (!inputValue.length) {
errorMessage = "Please Enter Any Numeric Value"
}
else {
k = new Number(inputValue)
if(isNaN(k)){
result = ""
errorMessage = "Please Enter Only Numbers"
}
else{
errorMessage = ""
if(fahrenheitCheck.getValue(true)){
k = (k - 32) / 1.8
s = k.toString(10)
result = s.substring(0,7) + " degrees Celcius"
}
else{
k = (1.8 * k) + 32
s = k.toString(10)
result = s.substring(0,7) + " degrees Fahrenheit"
}
}
}
}
// You can develop it seperately, but with two different converting buttons for each
// distinct conversions. Also, other component types might be used to do the similar
// thing easier and the script understandable.
Posted by: Mustafa Basgun | website
http://www.basgun.com
|
 |
 |
 |
color calculator (hex2dec // dec2hex)
 |
 |
//watch << the movie here: http://www.greencollective.nl/temp/download/colorcalculator.swf
//download << the movie here: http://www.greencollective.nl/temp/download/colorcalculator.zip
//**************************************************************************
function hex2rgb() {
//returns decimal color from hexadecimal (textfield) input("hexIn") for red & green & blue
//-->"HexIn" sliced up in 3 substrings
_root.redreturn = parseInt(hexIn.substring(0, 2), 16);
_root.greenreturn = parseInt(hexIn.substring(2, 4), 16);
_root.bluereturn = parseInt(hexIn.substring(4, 6), 16);
}
// and to to the other way: 3 inputs for R G & B (0 to 255) calculated
//to a Hexadecimal color. This function makes use of the two following.
function rgb2hex() {
hexR = dec2hex(_root.red);
hexG = dec2hex(_root.green);
hexB = dec2hex(_root.blue);
_root.returnhex = String(hexR)+String(hexG)+String(hexB);
}
function dec2hex(theDec) {
if (theDec>255) {
theDec = 255;
}
leftNum = Math.floor(theDec/16);
leftNumS = fixHex(leftNum);
rightNum = theDec%16;
rightNumS = fixHex(rightNum);
retNum = leftNumS+rightNumS;
return retNum;
}
function fixHex(theDec) {
hNum = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
retHex = hNum[theDec];
return retHex;
}
Posted by: Latcho | website
http://www.greencollective.nl/
|
 |
 |
 |
Convert from Mod 10 to Mod 2
 |
 |
function result(initialNumber) {
AAA = Array();
now = 0;
if (initialNumber == null) {
errorMessage = "Write something, dude!";
}
if (initialNumber < 0) {
errorMessage = "Write a meaningful number!";
} else {
while (true) {
foo1 = initialNumber/2;
foo2 = Math.floor(foo1);
if (initialNumber == 1) {
AAA[now] = 1;
break;
}
if (foo1 - foo2<>0) {
AAA[now] = 1;
} else {
AAA[now] = 0;
}
initialNumber = foo2;
now++;
}
}
foo3 = AAA.length;
result = "";
for (x=0; x < foo3; x++) {
result += AAA[(foo3-1)-x];
}
}
if (enteredNumber == "" || enteredNumber == undefined) {
enteredNumber = 15;
} else {
result(Number(enteredNumber));
}
Posted by: Mustafa Basgun | website
http://www.basgun.com
|
 |
 |
 |
Converting Polygons To Each Other
 |
 |
// Actually, this below code transforms triangle (3-sided polygon) to a
// 100-sided polygon. It can be used in a Flash movie which is designed
// to teach how to find the area of any circular region (infinite-sided
// polygon) by starting with the area of triangle.
// Posted Date: 16th December, 2002
k = 3;
movieClip.prototype.radian = function(angle) {
return (Math.PI/180)*angle;
};
movieClip.prototype.polygon = function(breadth, radius) {
degree = 360/breadth;
circle.createEmptyMovieClip("mainClip", 1);
with (circle.mainClip) {
moveTo(radius, 0);
beginFill(0xFF0000);
for (i=1; i<breadth; i++) {
posA = radius*(Math.cos(radian(i*degree)));
posB = radius*(Math.sin(radian(i*degree)));
lineTo(posA, posB);
}
endFill();
}
};
polygon(k, 50);
// Script for decreasing the number of sides:
decreaseButton.onRelease = function() {
if (k>3) {
numberOfSides = --k;
polygon(k, 50);
}
};
// Script for increasing the number of sides:
increaseButton.onRelease = function() {
if (k<100) {
numberOfSides = ++k;
polygon(k, 50);
}
};
Posted by: Mustafa Basgun | website
http://www.basgun.com
|
 |
 |
 |
<< Prev 5 |
Next
5