Jump to content
Search Community

Button Tweens

retropunk test
Moderator Tag

Recommended Posts

Hi everyone, pardon my code but I'm just starting out with these classes and I wanted to get feedback on these button functions.

What I notice is that if I rollover and out too quickly eventually the animation just hangs.

I'm thinking I'm using these wrong and there is a better way to interrupt the animations?

I am still learning so be gentle... thanks guys!

- btw the tint vaules are defined somewhere else in the code.

 

//button functions for the Click Button
gameResults.clickMeBtn.addEventListener (MouseEvent.ROLL_OVER, rollover, false, 0, true);
gameResults.clickMeBtn.addEventListener (MouseEvent.ROLL_OUT, rollout, false, 0, true);
gameResults.clickMeBtn.buttonMode=true;

function rollover (event:MouseEvent):void {
	TweenLite.to(gameResults.clickMeBtn.theBackground, .5, {tint:buttonColor});
	TweenLite.to(gameResults.clickMeBtn.theOutline, .5, {tint:bgColor});
}

function rollout (event:MouseEvent):void {
	TweenLite.to(gameResults.clickMeBtn.theBackground, .5, {tint:bgColor});
	TweenLite.to(gameResults.clickMeBtn.theOutline, .5, {tint:buttonColor});
}

Link to comment
Share on other sites

I didn't notice any obvious problems, so I wonder if there's something else going on in your code that's causing the problems. Or there's a slight chance that using weak references on your listeners is causing Flash's gc to kill them. If you're still running into trouble, please post an example FLA that demonstrates the problem (it can be a super simple one, not your production files). Don't forget to zip your file(s) before posting.

Link to comment
Share on other sites

interesting, I haven't had much experience with the weak reference. I'm gonna do some hard core testing and see what comes back.

I'll repost with my results, they could prove helpful. I've read and seen tutorials that say you should ALWAYS do false, 0, true for the 3rd, 4th and 5th parameters in an addEventListener. Especially the weak reference, it should ALWAYS be set to true. Maybe its not so black and white?

 

stay tuned.

Link to comment
Share on other sites

No, it's absolutely NOT an "always" thing. In fact, I just had to fix a bug in LiquidStage today that was caused by using a weak reference on a listener like that. Flash's garbage collector gobbled it up and suddenly my handler wasn't getting called.

Link to comment
Share on other sites

so would you say that the preferred practice is to always just remove listeners yourself? From what I understand in other languages you need to keep track of memory management yourself. Flash is unique in that it has a Garbage Collector doing it for you.

Link to comment
Share on other sites

so would you say that the preferred practice is to always just remove listeners yourself? From what I understand in other languages you need to keep track of memory management yourself. Flash is unique in that it has a Garbage Collector doing it for you.

 

Definitely - remove listeners yourself. You can still use weak references in many situations, though, but still remove the listeners when you're done with them.

Link to comment
Share on other sites

Definitely - remove listeners yourself. You can still use weak references in many situations, though, but still remove the listeners when you're done with them.

 

Yes, since working with AS3 I've been keeping with that best practice of removing listeners.

Thanks Jack

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