Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
American horizon

transmit the event dispatecher through "onComplete"

Recommended Posts

Hi

I want to know if is possible to launch a function through onComplete parameter, trasferring at the function the Object associated with the tween

 

For example:

TweenMax.to(supimg, 1, {x: posarrax[supimg.id], y:posarray[supimg.id], scaleY: 1, scaleX: 1, onComplete:riattivazoom})

 

launching the function "riattivazoom", i want to trasnfer to it "supimg", but without using the real name of the variable (supimg) because in the meantime it content could be changed!

I wanna be sure that tweenmax transfer at the function che precisious object thath have generated the "onComplete" event.

 

I hope you understood me, i'm italian

Link to comment
Share on other sites

Use onCompleteParams.

 

You pass an Array to it, like this:

 

TweenMax.to(pl3, 4, { scaleX: 1, scaleY: 1, x: pl3.IX - planetOffset, y: pl3.IY, onCompleteParams: [pl3], onComplete: FinishedZoomForObject  } );

 

In my code, I pass a 1-element Array where the "pl3" object is the single element. The receiving Function's signature has to look like this:

 

private function FinishedZoomForObject (pl: SomeObject): void

 

As you can see, [pl3] is an array. You can pass more things there. In that case, make sure your Function accept an Array argument, instead of SomeObject.

 

As for your reference problem: you will have to clone your object. Otherwise, the Function will always receive the CHANGED version (if it changes). Either clone it, either create a new reference every-time you need to and clean up the old reference in the onComplete function.

Link to comment
Share on other sites

i don't understand, what is "IX" and "IY" propriety?

and in what sense pl3 is an array? Why you use it?

Link to comment
Share on other sites

I don't know how your target of your tween is going to change after the tween is created, but I think you will find method 2 will be suitable

 

you can just smack this code into a file with objects mc_1 and mc_2

 

import com.greensock.*;
import com.greensock.events.TweenEvent;

//method 1 use onComplete callback and onCompleteParams

TweenLite.to(mc_1, 2, {x:400, onComplete:standardCallback, onCompleteParams:[mc_1]});


function standardCallback(something) {
trace("callBack");
trace(something);
trace(something.name);

/* output:

callBack
   [object MovieClip]
   mc_1

*/


}


//method 2 add EventListener

var boxTween:TweenMax = TweenMax.to(mc_2,3,{x:400});
boxTween.addEventListener(TweenEvent.COMPLETE, completeHandler);

function completeHandler(event:TweenEvent):void {
trace("\nEventListener");
trace("event: " + event);
trace("event.target: " + event.target);
trace("event.target.target: " +event.target.target);
trace("event.target.target.name: " +event.target.target.name);

/* output:

EventListener
event: [Event type="complete" bubbles=false cancelable=false eventPhase=2]
event.target: [object TweenMax]
event.target.target: [object MovieClip]
event.target.target.name: mc_2

*/


}

Link to comment
Share on other sites

IX and IY are some properties of mine. I just pasted something from one of my projects. You use whatever you have there.

 

pl3 is not an array. It is an element in an array:

 

[pl3] = array

 

onCompleteParams needs an array parameter.

Link to comment
Share on other sites

I don't know how your target of your tween is going to change after the tween is created, but I think you will find method 2 will be suitable

 

you can just smack this code into a file with objects mc_1 and mc_2

 

import com.greensock.*;
import com.greensock.events.TweenEvent;

//method 1 use onComplete callback and onCompleteParams

TweenLite.to(mc_1, 2, {x:400, onComplete:standardCallback, onCompleteParams:[mc_1]});


function standardCallback(something) {
trace("callBack");
trace(something);
trace(something.name);

/* output:

callBack
   [object MovieClip]
   mc_1

*/


}


//method 2 add EventListener

var boxTween:TweenMax = TweenMax.to(mc_2,3,{x:400});
boxTween.addEventListener(TweenEvent.COMPLETE, completeHandler);

function completeHandler(event:TweenEvent):void {
trace("\nEventListener");
trace("event: " + event);
trace("event.target: " + event.target);
trace("event.target.target: " +event.target.target);
trace("event.target.target.name: " +event.target.target.name);

/* output:

EventListener
event: [Event type="complete" bubbles=false cancelable=false eventPhase=2]
event.target: [object TweenMax]
event.target.target: [object MovieClip]
event.target.target.name: mc_2

*/


}

 

cool method

anyway in my case supimg change for a simple reason.. this is the code

 

function apriimg(evt:Event):void
{
if (evt.currentTarget!=supimg)
{
   if (supimg!=null)
         {TweenMax.to(supimg, 1, {scaleY: 1, scaleX: 1, x: posarrax[supimg.id], y: posarray[supimg.id], onComplete:riattivazoom})} //<---------- supimg tween starts

   supimg=evt.currentTarget //<-------supimg contens change in meanwhile
   TweenMax.to(evt.currentTarget, 0.5, {scaleY: 7, scaleX: 7, x: -250, y:100})
  }
}

 

then while supimg are tweening (it require 1 secondto complete operation) supimg change it contents

Link to comment
Share on other sites

pl3 is not an array. It is an element in an array:

[pl3] = array

 

onCompleteParams needs an array parameter.

 

you need to declare it or can just place the name of MC into square brackets?

Link to comment
Share on other sites

You can do it directly. In ActionScript 3, arrays can be declared inline when you first type [].

Link to comment
Share on other sites

You can do it directly. In ActionScript 3, arrays can be declared inline when you first type [].

then "pl3" is the instance name of a your MC placed on stage, and writing "[pl3]" you convert it in array? The conversion is necessary because tweenmax accepts only array to trasnfer, right?

Link to comment
Share on other sites

Yeap. You got that exactly right ::- ).

 

LATER EDIT:

 

I see in your code: posarrax[supimg.id], y: posarray[supimg.id]

 

Which means you have some Arrays for some internal use. Well, use those arrays to store in them the "supimg=evt.currentTarget".

 

posarraImages[supimg.id] = evt.currentTarget

 

Then:

 

TweenMax.to(whatever, 4, { whatever_You_want_to_tween, onCompleteParams: [posarraImages[supimg.id]], onComplete: YourFunctionHere[/b] } );

 

Then, in your onComplete Function code, don't forget to clean up the array elements which you don't use any more.

Link to comment
Share on other sites

Umh i don't understand

My situation is that i've an image grid, then every image have an x and y position that i've to keep trace

Then in posarrayx i trace the x position of the images and in posarray i trace the y position (it's like a matrix, but i've used two array)

 

This because i can zoom images clicking on it, and closing it, they have to return into initial position memorized into posarrayx and posarray

 

Now i haven't no array named "posarraImages"

Link to comment
Share on other sites

i seem to have missed a few comments but from what I can tell the advice that axon and I have given will work fine for you.

you don't need to use the eventListener (method 2) that i suggested. a simple onComplete with onCompleteParams will work fine.

 

please consider the following:

 


//point supimg to a movieclip instance
var supimg:MovieClip = mc2;

//storing start values
//you can use arrays/ids

mc2.initX = mc2.x;
mc2.initY = mc2.y;

TweenLite.to(supimg, 1, {x:300, onComplete:finish, onCompleteParams:[supimg]});

//immediately after tween starts change the value of supimg

supimg = this;


function finish(someObject){

//this function has no idea what supimg is
//it knows to tween mc2

TweenLite.to(someObject, 1, {x:someObject.initX, y:someObject.initY});

}

 

I attached a cs4 fla that you can test. the main point is that supimg can change after the tween starts but the onComplete function will know exactly what clip to tween back to its origin.

Link to comment
Share on other sites

Nevermind what I said. You don't need that array. You can just do as carl schooff showed you. You won't lose your reference. It was my mistake to add that new array. Just pass your image to onCompleteParams and you should be fine.

Link to comment
Share on other sites

i seem to have missed a few comments but from what I can tell the advice that axon and I have given will work fine for you.

you don't need to use the eventListener (method 2) that i suggested. a simple onComplete with onCompleteParams will work fine.

 

please consider the following:

 


//point supimg to a movieclip instance
var supimg:MovieClip = mc2;

//storing start values
//you can use arrays/ids

mc2.initX = mc2.x;
mc2.initY = mc2.y;

TweenLite.to(supimg, 1, {x:300, onComplete:finish, onCompleteParams:[supimg]});

//immediately after tween starts change the value of supimg

supimg = this;


function finish(someObject){

//this function has no idea what supimg is
//it knows to tween mc2

TweenLite.to(someObject, 1, {x:someObject.initX, y:someObject.initY});

}

 

I attached a cs4 fla that you can test. the main point is that supimg can change after the tween starts but the onComplete function will know exactly what clip to tween back to its origin.

 

cool works!

than trasnfering the paramters using [supimg], doesn't matter the real/actual content of supimg, the function only consider the tweened MovieClip

Link to comment
Share on other sites

Nice. Very glad you got it working.

 

Axonn, Thanks for all your help!

 

-carl

Link to comment
Share on other sites

What got my confused was my object-oriented C# thinking ::- D. I said that: Hm, if you pass a reference to a variable to TweenCore, then if you change that reference, when onComplete executes, the value you get in onComplete Params will also change. But it's not like this because the vars object of the Tween gets saved internally in the TweenCore, so the original reference is kept. The variable is simply used as a vessel to feed that reference to TweenCore.

 

Correct me if I'm wrong.

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