Procedure:
step 1: Open flash 8
step 2: Select flash document
step 3: select 1st layer, 1st frame on that document and write source code on Actions Frame
step 4: To check output press ctrl+enter(test movie)
Source code:
function convertTemperature(fMeasure, tMeasure, val)
{
fMeasure = fMeasure.toLowerCase( );
tMeasure = tMeasure.toLowerCase( );
if ( (fMeasure == "centigrade" || fMeasure == "celsius" || fMeasure == "c")
&& (tMeasure == "fahrenheit" || tMeasure == "f") )
{
return (val * 9/5) + 32;
}
else if ( (fMeasure == "fahrenheit" || fMeasure == "f") &&
(tMeasure == "centigrade" || tMeasure == "celsius" || tMeasure == "c") )
{
return (val - 32) * 5/9;
}
else
{
trace ("Invalid conversion type from " + fMeasure + " to " + tMeasure);
return NaN;
}
}trace("----------------------------------------------------------------------");
trace("converting 32 from centigrade to fahrenheit:"+convertTemperature("c","f",32));
trace("converting 64 from fahrenheit to centigrade:"+convertTemperature("f","c",64));
trace("----------------------------------------------------------------------");
function convertToCentigrade(fMeasure, val)
{
fMeasure = fMeasure.toLowerCase( );
if (fMeasure == "kelvin" || fMeasure == "k")
{
return (val - 273.15);
}
else if ( fMeasure == "fahrenheit" || fMeasure == "f" )
{
return (val - 32) * 5/9;
}
else if (fMeasure == "centigrade" || fMeasure == "celsius" || fMeasure == "c")
{
return val;
}
else
{
return NaN;
}
}
trace("----------------------------------------------------------------------");
trace("converting 78 from kelvin to centigrade:"+convertToCentigrade("k",78));
trace("converting 38 from fahrenheit to centigrade:"+convertToCentigrade("f",38));
trace("displaying the celsius value:"+convertToCentigrade("c",60));
trace("----------------------------------------------------------------------");
function convertFromCentigrade(tMeasure, val)
{
tMeasure = tMeasure.toLowerCase( );
if (tMeasure == "kelvin" || tMeasure == "k")
{
return (val + 273.15);
}
else if ( tMeasure == "fahrenheit" || tMeasure == "f" )
{
return (val * 9/5) + 32;
}
else if (tMeasure == "centigrade" || tMeasure == "celsius" || tMeasure == "c")
{
return val;
}
else
{
return NaN;
}
}
trace("----------------------------------------------------------------------");
trace("converting centigrade value 42 to kelvin:"+convertFromCentigrade("k",42));
trace("converting centigrade value 56 to farhenheit:"+convertFromCentigrade("f",56));
trace("displaying celsius value:"+convertFromCentigrade("c",72));
trace("----------------------------------------------------------------------");
/*function convertTemperature(fMeasure, tMeasure, val)
{
var centigradeVal = Math.convertToCentigrade (fMeasure, val);
return Math.convertFromCentigrade (tMeasure, centigradeVal );
}*/
function convertWeights(fMeasure, tMeasure, val)
{
if (fMeasure == "pounds" && tMeasure == "kilograms")
{
return val / 2.2;
}
else if (fMeasure == "kilograms" && tMeasure == "pounds")
{
return val * 2.2;
}
else
{
return "invalid conversion type";
}
}
trace("----------------------------------------------------------------------");
trace("converting 98 from pounds to kilograms:"+convertWeights("pounds","kilograms",98));
trace("converting 89 from kilograms to pounds:"+convertWeights("kilograms","pounds",89));
trace("----------------------------------------------------------------------");
step 1: Open flash 8
step 2: Select flash document
step 3: select 1st layer, 1st frame on that document and write source code on Actions Frame
step 4: To check output press ctrl+enter(test movie)
Source code:
function convertTemperature(fMeasure, tMeasure, val)
{
fMeasure = fMeasure.toLowerCase( );
tMeasure = tMeasure.toLowerCase( );
if ( (fMeasure == "centigrade" || fMeasure == "celsius" || fMeasure == "c")
&& (tMeasure == "fahrenheit" || tMeasure == "f") )
{
return (val * 9/5) + 32;
}
else if ( (fMeasure == "fahrenheit" || fMeasure == "f") &&
(tMeasure == "centigrade" || tMeasure == "celsius" || tMeasure == "c") )
{
return (val - 32) * 5/9;
}
else
{
trace ("Invalid conversion type from " + fMeasure + " to " + tMeasure);
return NaN;
}
}trace("----------------------------------------------------------------------");
trace("converting 32 from centigrade to fahrenheit:"+convertTemperature("c","f",32));
trace("converting 64 from fahrenheit to centigrade:"+convertTemperature("f","c",64));
trace("----------------------------------------------------------------------");
function convertToCentigrade(fMeasure, val)
{
fMeasure = fMeasure.toLowerCase( );
if (fMeasure == "kelvin" || fMeasure == "k")
{
return (val - 273.15);
}
else if ( fMeasure == "fahrenheit" || fMeasure == "f" )
{
return (val - 32) * 5/9;
}
else if (fMeasure == "centigrade" || fMeasure == "celsius" || fMeasure == "c")
{
return val;
}
else
{
return NaN;
}
}
trace("----------------------------------------------------------------------");
trace("converting 78 from kelvin to centigrade:"+convertToCentigrade("k",78));
trace("converting 38 from fahrenheit to centigrade:"+convertToCentigrade("f",38));
trace("displaying the celsius value:"+convertToCentigrade("c",60));
trace("----------------------------------------------------------------------");
function convertFromCentigrade(tMeasure, val)
{
tMeasure = tMeasure.toLowerCase( );
if (tMeasure == "kelvin" || tMeasure == "k")
{
return (val + 273.15);
}
else if ( tMeasure == "fahrenheit" || tMeasure == "f" )
{
return (val * 9/5) + 32;
}
else if (tMeasure == "centigrade" || tMeasure == "celsius" || tMeasure == "c")
{
return val;
}
else
{
return NaN;
}
}
trace("----------------------------------------------------------------------");
trace("converting centigrade value 42 to kelvin:"+convertFromCentigrade("k",42));
trace("converting centigrade value 56 to farhenheit:"+convertFromCentigrade("f",56));
trace("displaying celsius value:"+convertFromCentigrade("c",72));
trace("----------------------------------------------------------------------");
/*function convertTemperature(fMeasure, tMeasure, val)
{
var centigradeVal = Math.convertToCentigrade (fMeasure, val);
return Math.convertFromCentigrade (tMeasure, centigradeVal );
}*/
function convertWeights(fMeasure, tMeasure, val)
{
if (fMeasure == "pounds" && tMeasure == "kilograms")
{
return val / 2.2;
}
else if (fMeasure == "kilograms" && tMeasure == "pounds")
{
return val * 2.2;
}
else
{
return "invalid conversion type";
}
}
trace("----------------------------------------------------------------------");
trace("converting 98 from pounds to kilograms:"+convertWeights("pounds","kilograms",98));
trace("converting 89 from kilograms to pounds:"+convertWeights("kilograms","pounds",89));
trace("----------------------------------------------------------------------");
No comments:
Post a Comment