The Title that sounds to be the start of some drama or story will most probably does not have a epilogue for this world of ActionScript is so vast that it will not drain and chances are that it may not have a epilogue. (whew : it was just an opinion).
As this is the first time i am starting to blog and also wondering what to post (This is what has been making me not a blooger all this time i.e., "First Time").
i hereby start with a tip on the essence of Mathematics in programming.
Imagine you have a MovieClip , a Button and a Boolean variable. Now when the button is clicked we will set the bool to true or false respectively. Based on the Boolean value we need to set the alpha state of the button to 30(if false) or 100(if true) respectively.
Yeah i know what you are thinking. Just set a if and else condition that will control the alpha of the button. But dont tell me it is the only way we always need to do it.
To make things clear we will start it with the general way of Scripting.
Intially the MovieClip alpha is at 100.
//Actions on the timeLine
var bool:Boolean = true;
function setAlphaState()
{
if(bool)
{
mc._alpha = 100;
}
else
{
mc._alpha = 30;
}
}
//Actions on the button()
on(press)
{
bool = !bool;
setAlphaState();
}
But again the same setAlphaState function can be written as below thereby reducing the processing.
function setAlphaState()
{
if(!bool)
{
mc._alpha = 30;
return;
}
mc._alpha = 100;
}
Hence there are lot of ways that might emerge to write this piece of process using if and else conditions.
Imagine doing this mathematically,
function setAlphaState()
{
mc._alpha = (Number(bool) *(100-30)) +30 ;
}
Dont you think the above way will work ????? Try it and check it out.
Basically i am a guy who believes that using these if and else conditions actually make your application weak.
The Reason : When a scenario has to dealt with and if we are goin to use our head to analyse the situation we tend to miss out some micro situations and may not present these conditions in the if else part and hence as a result our programs tends to fail at a point.
But on the contrary when we analyze the scenario and get a Mathematical part that can govern the scenario and deal it in the natural way then there are less chances than that of if else way for failing.
Hence this way my blog starts with a note to why we need to use Mathematical methods to deal with scenarios than using wasting time to analyze the micro macro sub scenarios and write it on our own. (This cannot be applied all the time but should implement when we actually can )
Hope my first blog was not sounding so stupid for any advanced readers reading this and neither very advanced to those beginners also reading this.
ReGaRdS,
Ashok Srinivasan.
Search Box
Wednesday, September 20, 2006
Subscribe to:
Post Comments (Atom)
2 comments:
I was just thinking of having another approach to the same solution.
on(press){
setAlphaState()
}
function setAlphaState(){
mc._alpha = (mc._alpha <30)?100:30;
}
Looking for more post from you Ashok. You have always been an eyeopener
I can be reached @ My other blog
http://vinodvv.wordpress.com
Post a Comment