Read More Ninja Action!

Quick Tip: Inline functions with Tweener and addTween

Hi everyone, here is a really quick tip for Tweener users. I just came across the following situation in a contract. I had to move something to the side of the stage with Tweener, and then set the visible to 0 to prevent users from clicking hidden buttons that were inside the clip. So, to move off the stage I just used this tween:

Tweener.addTween(page1Content, {alpha:0, x:-266, time:1, onComplete:hidePage1Content});

See how lunky that is at the end? I really don't want to have to write a whole function just to turn the thing off, but there isn't a way around that given the timing of Tweener. It HAS to wait until the Tween is complete. So, after a bit of thinking and digging I was able to add an inline function to do this for me and save me some function writing. This is what I ended up with:

Tweener.addTween(page1Content, {alpha:0, x:-266, time:1, onComplete:function() { this.visible = false; }});

Now the inline function runs right after the content fades out with no additional function writing necessary.
Easy!