Jump to content
Search Community

How to get targets coordinates (on the fly) ?

SudoPlz test
Moderator Tag

Recommended Posts

I would like to get my target and access its properties (while tweening).

I tried onUpdate func etc, but I can't seem to get the target out of the event.

Se below to understand what im talking about.

 

tileMovement.insert( TweenLite.to(target, 1, {y:-(tileHeight*2), scale:2, ease:Elastic.easeIn, onUpdate: deebreeStart})
for (var x:uint =0 ; x< 3; x++){
deebree = particles.createDeebreeParticlesAt( target.x , target.y );
deebree.start(1);
}

 

 

function deebreeStart(evt:TweenEvent):void {

 trace( evt.target.x);

}

This results on

ArgumentError: Error #1063: Argument count mismatch on Function/deebreeStart(). Expected 1, got 0.

 

 

 

To tell the whole story, I wan't to get some particles to follow a few tiles while they are moving. That why I need to access the tiles properties.

Any suggestions?

Link to comment
Share on other sites

Yes, the onUpdate callback is not handled like an as3 native Event. It is simply a function that is being called, not an Event that is being fired.

 

If you use TweenMax, you can use

 

someTweenMaxTween.addEventListener(TweenEvent.UPDATE, deebreeStart);


function deebreeStart(evt:TweenEvent):void {
//the target of a TweenEvent is the tween that fired the event. The target of a tween is the object that is being tweened.
    trace( evt.target.target.x);

}

 

 

 

 

 

Or, using v12 you can now self-reference the tween/timeline in the onCompleteParams, onUpdateParams, onstartParams, onreverseCompleteParams, or onrepeatParams using the special keyword “{self}”. For example:

 

TweenLite.to(mc, 1, {x:100, onUpdate:reportTime, onUpdateParams:["{self}"]});
function reportTime(tween:TweenLite) {
   trace("time: " + tween.time() + ", target: " + tween.target);
}

This works with all callbacks in TweenLite, TweenMax, TimelineLite, and TimelineMax.

  • Like 1
Link to comment
Share on other sites

One other simple solution for you (which works in any version of TweenLite) is to pass the target using onUpdateParams like:

 

 

tileMovement.insert( TweenLite.to(target, 1, {y:-(tileHeight*2), scale:2, ease:Elastic.easeIn, onUpdate: deebreeStart, onUpdateParams:[target]})

function deebreeStart(mc:DisplayObject):void {
 trace(mc.x);
}

  • Like 1
Link to comment
Share on other sites

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