PDA

View Full Version : Path issue with function?



wyclef
April 29th, 2004, 06:58 PM
Does anyone know how I can take the following script from the root level and invoke the functions within an MC?



//initiate timer paramaters
timerInit = function() {
//getting the time at this point
startTime = getTimer()/1000;
//setting the waiting period
waitFor = 3;
//5 seconds
}

//start the timer
timerPause = function () {
if (waitFor>((getTimer()/1000)-startTime)) {
gotoAndPlay("pause");
} else {
gotoAndPlay("begin");
}
}

lunatic
April 29th, 2004, 07:01 PM
Put the functions on the timeline of the MC?

wyclef
April 29th, 2004, 07:29 PM
but if i'm using the function within multiple different MCs i'd like to be able to do it without duplicating the same script over and over again.

The Mullah
April 29th, 2004, 09:26 PM
use prototype functions?

nunomira
April 29th, 2004, 10:26 PM
using absolute notation (not advisable):


_root.timerInit();
_root.timerPause();

using relative notation:


_parent.timerInit();
_parent.timerPause();
// or
_parent._parent.timerInit();
_parent._parent.timerPause();
// or
....
// depending from where you're calling the function


In MX, there should be no need to call functions from other places other than the main timeline, where the function is defined, as all the code should be attached to that very same timeline.
Read understanding target paths (http://www.nunomira.com/tutorials/) for more details.

wyclef
April 30th, 2004, 11:40 AM
it seems like when I do this the function doesn't understand that


if (waitFor>((getTimer()/1000)-startTime)) {
gotoAndPlay("pause");
} else {
gotoAndPlay("begin");
}
}


the gotoandplays apply to within the MC the function is invoked.

nunomira
April 30th, 2004, 01:07 PM
Yes, that's correct.
You may pass the movie clip you want to control as parameter, or, like suggested, using prototype.

a)


function timerPause(mc)
{
if (waitFor > ((getTimer() / 1000) - startTime)) {
mc.gotoAndPlay("pause");
} else {
mc.gotoAndPlay("begin");
}
}
// example:
timerPause(some_mc.other_mc);


b)


MovieClip.prototype.timerPause = function()
{
if (waitFor > ((getTimer() / 1000) - startTime)) {
this.gotoAndPlay("pause");
} else {
this.gotoAndPlay("begin");
}
};
// example:
some_mc.other_mc.timerPause();

wyclef
April 30th, 2004, 02:51 PM
Can someone take a look at this fla and tell me how to fix it? The troubled functions are within the "timer" layer on frame 25. Currently, those functions aren't called specifically, I just duplicate the function code within each of the MCs on the section layer. If you open one up you will see the functioning code on frame "start" and "pause". That code works, but since it's duplicated 7 times I want to figure out how to run the function from the script on the root level instead. I'm not having any luck. Let me know what y'all think?