Skip to main content
Inspiring
March 25, 2009
Answered

Buttons randomly not working with tween

  • March 25, 2009
  • 3 replies
  • 709 views
The website I'm creating has a large map picture (mcMap) and a crosshair (mcLines) that moves to a different location, depending on which button is clicked. I used a Switch statement and the Point and Tween classes so the user can click from one to the other and the map and craosshair moves.

However, when a button is clicked...sometimes, at random, the map and/or crosshair goes to the wrong location and/or the MC that is supposed to appear doesn't. The issue is very random, so I'm lost as to what may cause this.

Any help is GREATLY appreciate - this is the last step in finishing the site. Here's my code:
This topic has been closed for replies.
Correct answer RRebel
Thanks for your response, I tried creating two different switch statements (one for the mcMap and mcLines tweens and one for the movieclips that need to appear, such as company, services, etc) using the code you posted, but I am still having trouble with the MCs not appearing. The buttons call the tween function on MOUSE_DOWN and show MC function on CLICK. I took your advice and created a trace and the function is being called everytime, but the MC doesn't always appear.

Do you have any idea how the MC doesn't appear, even if the function is being called? I've attached my new code - thanks for your help with this.

I figured it out, a problem with the Tween class is that the garbage collector sometimes sweeps information while the tweens are still playing.

I downloaded a custom Tween class at http://exanimo.com/actionscript/never-use-tween-or-urlloader/ and haven't had any problems so far.

Thanks for your help Craig.

3 replies

Craig Grummitt
Inspiring
March 25, 2009
That's the one! Either assign your Tweens to persistent variables as you've illustrated, or you could use Tweener for all your Tweens.
RRebelAuthor
Inspiring
March 25, 2009
So, instead of using "new Tween" for each tween, should it look more like:

var tweenLinesSDx: Tween;
var tweenLinesSDy: Tween;

function contentLoader(e:MouseEvent):void {
switch(e.target.name) {
case "btnSDMain":
currentRequest = mcSDnested;
tweenLinesSDx = new Tween (mcLines, 'x', null, mcLines.x, linesSD.x, 1, true);
tweenLinesSDy = new Tween (mcLines, 'y', null, mcLines.y, linesSD.y, 1, true);
etc....

Correct? I tried this with those two variables and no problems so far. Thanks for your help.
Craig Grummitt
Inspiring
March 25, 2009
disclaimer: i haven't gone through your code in too much detail. i just noticed that you have declared several Tweens there but not assigned them to variables, let alone persistent variables. This means you put the fate of these Tweens in the hands of garbage collection and you can lose those Tweens at any time. When i first encountered this problem, it also seemed to produce frustratingly random results, so hopefully this helps.
RRebelAuthor
Inspiring
March 25, 2009
Ok, so the map and lines move everytime, so it looks like that is fixed, but there is one problem still.

When you click a button (e.g., 'btnSDMain'), it is supposed to load the movie clip (e.g., 'mcSDnested'), but at random times it doesn't show the MC. I'm sure the solution is probably similar to the other problem, but I'm pretty new to AS3 and at a loss.
Craig Grummitt
Inspiring
March 26, 2009
Don't know sorry. I've recreated your code - well the section where the error should be occurring(see attached), and its not. Have you put a trace in the loadit function to check that its reaching there okay? No runtime errors appearing in the output window? Tried commenting out all the tweens to see if they're effecting the outcome somehow?