Jump to content
Search Community

Passing on the Object to the function

_maxxy test
Moderator Tag

Recommended Posts

Hi,

 

as usual, thanks so much for making life of the developers so much easier, you are a start Jack!

 

My question:

Imagine I have a multiple tweens for different objects which all have the same function called on onComplete.

In this function, I would like to cache the previously tweened object.

 

My problem lies in how to pass on the Object into the function so that it gets cached. I can simply copy the name of the object and that works but I was looking for a more dynamic way.

 

Working example:

 

TweenMax.to(M, 1,{x:500, onComplete:CACHE, onCompleteParams:[M]});

function CACHE(THIS:Object){
THIS.cacheAsBitmap = true;
trace(M.cacheAsBitmap)

}

 

Now, I would like to substitute the "M" in the onCompleteParams with some sort of "variable" because M is a very long name of the path to the desired mc and is always quite different (unlikely to be shortened using a variable etc.)

 

Thanks in advance everyone.

m.

Link to comment
Share on other sites

I'm confused - M is a String? The name of the object? If that's true, your tween won't work anyway because you're using M as the target and you can't tween a String. Maybe you meant something like this?:

 

TweenMax.to(myObject, 1,{x:500, onComplete:CACHE, onCompleteParams:[myObject]});

function CACHE(THIS:Object){
  THIS.cacheAsBitmap = true;
  trace(M.cacheAsBitmap)
}

 

You're welcome to use a variable and plug that into the onCompleteParams array if you want. Sorry if I'm misunderstanding your question.

Link to comment
Share on other sites

my bad.

 

but yes, you are correct. M is the object i.e. "mainMC.mc2.mc3.mc4.M"

The question is if instead of just copying and pasting this into the onCompleteParams i.e. onCompleteParams:[mainMC.mc2.mc3.mc4.M] (which does the job) I could write something universal which would pass on the tweened object's name to the CACHE function too.

 

So instead of typing in the object's name, I would like to use something in the sense of "currentTarget" ...see what I mean?

 

thanks again and sorry for causing you a headache, as you can tell, I'm not a programmer :D

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