Forum Moderators: open

Message Too Old, No Replies

passing an action to a function

         

benihana

2:20 pm on Dec 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ive written a simple timer function that i can just call if i want to .eg. pause something for a shortwhile.

Im wanting to be able to call it like so:


timer (time, action);

where time is the milliseconds to time, and action is what to do when the times up; e.g.

timer (5000, '_root.mcInstance.play();');

however, i dont how to get the function to do the:

_root.mcInstance.play();

bit.

I thought just putting action; in the approriate place would do it.

Ive tried all sorts of things but to no avail.

Any pointers? :(

benihana

4:50 pm on Dec 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For completeness - ive got it sorted.

I split the action i wanted to take up into the path and what i wanted it to do:

//#### TIMER FUNCTION
timer = function (time, path, action) {

current = getTimer();

onEnterFrame = function () {
now = getTimer();

comp = (current)+time;

if (comp<=now) {

_root[path][action]();

delete this.onEnterFrame;
}
};
};

and called it like this:

_root.timer(5000, "instancename", "play")

if i need to do anything more complex than stop or play afterwards, i will could the action in another mc and use the play() to access that.