Jump to content
Search Community

function shorthand?

grimey test
Moderator Tag

Recommended Posts

Hey!

 

Can TweenMax condense the syntax for functions similar to this:

 

TweenMax.to(mc,.5,{x:10,onComplete:function() { 
  // do something when the tween is complete;
});

 

Some kind of of shorthand for these functions would be a great time/code saver.

 

Thank you so much for TweenMax! It makes my customers' dreams come true!

 

:grimey

Link to comment
Share on other sites

Using anonymous functions like that is considered a poor coding practice, just so you know. It can cause garbage collection issues in Flash (has nothing to do with TweenLite/Max specifically) and it's just kinda ugly. There's not a shorthand way to do what you're trying to do (at least not that I know of). You should use regular functions like:

 

TweenMax.to(mc,.5,{x:10,onComplete:onFinishTween});
function onFinishTween():void {
  // do something when the tween is complete;
}

 

If you're trying to sequence things, I'd highly recommend checking out the TimelineLite and TimelineMax classes which make it super easy. http://blog.greensock.com/timeline-basics/. Have fun.

Link to comment
Share on other sites

Thanks for the info. I wasn't aware of the garbage collection problem. I'll have to rethink my strategy.

 

My only hope was to avoid having a separate function to remove a child after it's faded out or slid off the stage or something.

Link to comment
Share on other sites

Tip: If you're worried about having to create a function for each tween that basically does the same thing but for different targets, just use the onCompleteParams and a more generic function, like:

 

TweenMax.to(mc,.5,{x:10,onComplete:removeTarget, onCompleteParams:[mc]});
function removeTarget(target:DisplayObject):void {
  target.parent.removeChild(target);
}

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