Jump to content
Search Community

multiple events triggered from onComplete?

bonassus test
Moderator Tag

Recommended Posts

Would Someone please help me i'm stuck. I'm new to as3 and need a little help. I have set up a test file with an mc ball and set up a simple tween using tweenlite to move the ball 100 pixels. I am using the onComplete parameter to run a function called myFunction. This works. What I would like to do is be able to trigger more then one function with the completion of the tween so that myfunction and myOtherfunction both run. I tried to set up an addEventListener to respond to the onComplete but im not sure what to attach it to(where i have the ? in the code). Am I going about this the wrong way? can someone point me in the right direction? please see code below:

 

package  {

	import com.greensock.*;
import com.greensock.easing.*;
import flash.display.MovieClip

public class Test extends MovieClip {

	public function Test() {

	var ball:Ball = new Ball();
	ball.x = 200;
	ball.y = 200;
	addChild(ball);
	TweenLite.to(ball, 1, {x:200, y:100, onComplete:myFunction});

	function myFunction():void {
   	trace("tween finished");
	}

	?.addEventListener(TweenEvent, myOtherFunction);

	function myOtherFunction():void {
   	trace("Other tween finished");
	}


	}

}

}

Link to comment
Share on other sites

The simplest way would be to use an onComplete to call a function that in turn calls whatever other functions you want. Kinda like:

 

TweenLite.to(mc, 1, {x:100, onComplete:myProxyFunction});
function myProxyFunction():void {
   myFunction1();
   myFunction2();
}

 

If you want to use event listeners, then you need to switch to TweenMax because TweenLite doesn't do event dispatching. In that case, you'd do something like:

 

var myTween:TweenMax = new TweenMax(mc, 1, {x:100});
myTween.addEventListener(TweenEvent.COMPLETE, myFunction1);
myTween.addEventListener(TweenEvent.COMPLETE, myFunction2);

Link to comment
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...