...

View Full Version : function complete event?



tyler jones
09-10-2008, 07:27 PM
Is there a way to listen for a function to complete? I have a page that has a small animation that plays when certain links are clicked. Everytime the animation completes I need to call a different function that is specific to whatever link was clicked. So it's like I need my animation function to throw a completed event that I can listen for. So for example I'd want to do something like...

<a href="javascript:OnAnimationComplete(FunctionToCall);StartAnimation()">start</a>

OnAnimationComplete would set a listener for that complete event and then call the FunctionToCall function when it received the event. Thanks.

Philip M
09-10-2008, 08:13 PM
Not sure if this meets your needs:-

(Function A is startAnimation(), Functions B and C are the functions to run after A)


<a href= "javascript:A(); B()">Link to A and B</a><br>
<a href= "javascript:A(); C()">Link to A and C</a><br>

<script type = "text/javascript">
var num = 0;
function A() {
for (var i = 1; i<=3; i++) {
alert ("Here is function A Loop " + i);
}
}

function B() {
alert ("Function B runs after A has finished")
}

function C() {
alert ("Function C runs after A has finished")
}

</script>

See also:-

http://www.codingforums.com/showthread.php?t=24929



Quizmaster: In Roman Catholicism, baptism, confirmation and matrimony are three of the seven what?
Contestant: Deadly sins.

tyler jones
09-10-2008, 08:50 PM
In my case it's a simple example but in reality of what is going on in my page it isn't done as easily as what I illustrated. The actual animation is a class that instantiates and adds a div to the bottom of the page. During it's creation it also goes through the page and any link that has a rel="shadow" applied to it, it wires up a click handler to start it's own animation. So, I'm not necessarily starting the animation like


<a href="javascript:startanimation">start</a>

but instead it looks like


<a href="#" rel="shadow">start</a>

So what I'd like to do is put something in that animation function that is contained in the class that fires an event that my link can listen for. So it would actually look like


<a href="javascript:SetUpListener(FunctionToCallA);" rel="shadow">start a</a>
<a href="javascript:SetUpListener(FunctionToCallB);" rel="shadow">start b</a>

rnd me
09-10-2008, 11:22 PM
you could add a property to you rclass that the function changes right before the return.

since events are functions, you can also simply call or return the event invocation to chain it.

eg:

function animate(){
//do stuff here
return animationDone()
}

rnd me
09-10-2008, 11:23 PM
you could add a property to you rclass that the function changes right before the return.

since events are functions, you can also simply call or return the event invocation to chain it.

eg:

function animate(){
//do stuff here
return animationDone()
}

Philip M
09-11-2008, 08:30 AM
you could add a property to you rclass that the function changes right before the return.

since events are functions, you can also simply call or return the event invocation to chain it.

eg:

function animate(){
//do stuff here
return animationDone()
}


Yes, but the OP wants to call a different function after animate() depending on which link was clicked.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum