Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-10-2008, 06:27 PM   PM User | #1
tyler jones
New Coder

 
Join Date: Jul 2002
Posts: 47
Thanks: 1
Thanked 0 Times in 0 Posts
tyler jones is an unknown quantity at this point
function complete event?

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.
tyler jones is offline   Reply With Quote
Old 09-10-2008, 07:13 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Not sure if this meets your needs:-

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

Code:
<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.

Last edited by Philip M; 09-10-2008 at 07:17 PM..
Philip M is offline   Reply With Quote
Old 09-10-2008, 07:50 PM   PM User | #3
tyler jones
New Coder

 
Join Date: Jul 2002
Posts: 47
Thanks: 1
Thanked 0 Times in 0 Posts
tyler jones is an unknown quantity at this point
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

Code:
<a href="javascript:startanimation">start</a>
but instead it looks like

Code:
<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

Code:
<a href="javascript:SetUpListener(FunctionToCallA);" rel="shadow">start a</a>
<a href="javascript:SetUpListener(FunctionToCallB);" rel="shadow">start b</a>
tyler jones is offline   Reply With Quote
Old 09-10-2008, 10:22 PM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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:
Code:
function animate(){
  //do stuff here
  return animationDone()
}
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 09-10-2008, 10:23 PM   PM User | #5
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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:
Code:
function animate(){
  //do stuff here
  return animationDone()
}
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 09-11-2008, 07:30 AM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by rnd me View Post
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:
Code:
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
tyler jones (09-11-2008)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:33 AM.


Advertisement
Log in to turn off these ads.