Search Box

Google
 

Thursday, September 21, 2006

CHAPTER 1

The start of the day was really nice with the orange ball whose surface temperature known to be 5800K just shooting up in the sky. Was really nice to see him on the rise. So had my quick breakfast and was making my way to work.

Soon after i landed i opened flash and geared up to look at it for the rest of the day. Soon i remembered about sterday where my colleague had a problem using those absolute paths to refer the movieclips due to which the heads were rolling on the floor with our dealine coming to a deadend.

I am an actionscript developer who is basically against using all those absolute paths and am comfortable using relative paths.

But the problem right in front was due to the fact of utter laziness. Seems to be like the movieClip was emerging around 7-8 levels inside the stage. (like _level0.instance1.instance2.instance3.instance4.instance5.instance6.mc);.


here we had to make a function call that resides in the level0 but were unable to coz the movie that we are publishing is just one of the swfs that gets loaded in another swf. and this might change sometime in the future. As i had faced all these scenarios 2 years before itself the experience helped me and i decided on that fine day that i will never use any absolute scoping but only relative mapping at any cost.

Now here is what i did to solve this problem. The movieclip instance from where i needed to call the function was a subchild of order 7 in a main instance on the stage called "$holder". So if we need to access the stage's timeline variables or functions we need to probably call like this

this._parent._parent._parent._parent._parent._parent._parent._parent.funcXYZ();

or

_level0.funcXYZ();

As i said earlier it is my principle that i will not use the second method(absolute pathing method).

So would i use the first method >???? NO !

Better i will device a prototype such that i will be able to use it to handle all the similar problems.

The solution was like this. But before that i had laid a simple rule that the last parent MC i.e., on the stage timeline will have an instance name and no other subparents inside it will have .

cool ? let's get back to the prototype.

MovieClip.prototype.findTheParent = function(whoseNameIs:String):MovieClip
{
var mc:MovieClip = this;
while(mc._name != whoseNameIs)
{
mc = mc._parent;
}
return mc;
}

So now coming to the part where this helped actual scenario being implemented, it was like using this way.....

this.findTheParent("$holder")._parent.funcXYZ();

instead of the below already above mentioned METHODS !@!!!!!!!
{
this._parent._parent._parent._parent._parent._parent._parent._parent.funcXYZ();

or

_level0.funcXYZ();
}



Hope this helps you all !. But sure it helped me!

ReGaRdS,

Ashok Srinivasan.

Wednesday, September 20, 2006

Prologue !

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.