Jump to content
Search Community

TweenMax.to starts in the wrong position

tpann test
Moderator Tag

Recommended Posts

Hello,

 

New to GSAP and new to this forum. This question has probably been answered many times but I don't know the appropriate key words to use to ask the question so I have not found a solution.

 

I have a rather large Flash app (large and proprietary to my job so I can't post it here) in ActionScript 3 that uses a TweenMax.to statement. The tween is not working as I prefer. The app works like this: There is a "window" (just a visual box) that rectangular objects get added to over time. As they're added, they stack, with new ones going to the bottom of the stack. Once the stack gets too big for all objects to display in the window, the stack is supposed to tween upward to display the bottom object.

 

I have reproduced the basic functionality in a simpler set of code so you can see how it works:

import flash.display.Shape;
import flash.display.Sprite;
import flash.events.MouseEvent;
import com.greensock.*;
import com.greensock.easing.*;


var boxArray:Array = new Array();
var windowHeight:Number = 300;

var window:Sprite = new Sprite();
window.graphics.lineStyle(1);
window.graphics.drawRect(0, 0, 400, 300);
addChild(window);
window.x = 100
window.y = 200;

var stack:Sprite = new Sprite();
window.addChild(stack);

button.addEventListener(MouseEvent.CLICK, addBox);
function addBox(m:MouseEvent):void {
	var box:Shape = new Shape();
	box.graphics.beginFill(Math.random()*0xFFFFFF);
	box.graphics.drawRect(0, 0, 200, 40);
	stack.addChild(box);
	box.x = 10;
	if (boxArray.length == 0) {
		box.y = 10;
	} else {
		box.y = boxArray[boxArray.length-1].y + boxArray[boxArray.length-1].height + 10;
	}
	boxArray.push(box);
        // if the new box is below the bottom of the window, tween upward to bring it into view
	if (stack.y + stack.height > windowHeight) {
		TweenMax.to(stack, 0.5, {y:-stack.height + windowHeight - 10});
	}
}

[The only thing you have to do beyond pasting this into the Flash IDE is add a button to the stage and call it "button."]

I was hoping this little example would have the same problem that I'm having in my bigger application but as luck would have it this works perfectly. :) However this enables me to explain my problem better:

In my application, whenever a new object is added to the stack, the TweenMax.to statement moves the stack to stack.y = 0, meaning it jumps instantaneously all the way back down to y=0 AND THEN tweens all the way back up to the correct position. Of course this is not what I want -- I want it to look like the above example.

I have tried casting the y parameter as a String but I get the same behavior.

Can anyone provide some insight into what I might change to make my bigger application work like the one I've posted here?

Thank you,
Tim

Link to comment
Share on other sites

It is indeed tough to troubleshoot blind, so if you could create a reduced test case that demonstrates the issue, that'd be really helpful. A few other thoughts:

  1. Did you check to see what your object's "y" is right before you create the tween? I suspect it is 0. TweenMax does NOT force things back to 0 initially - it simply starts from wherever the value is at the start of the tween.
  2. If you want the tween to be relative, add "+=" or "-=" as the prefix, like {y:"+=20"} would move it 20 pixels to the right of wherever it is. 
  3. Maybe you've got your object positioned on a keyframe in the Flash IDE that's forcing it to 0 or something. In other words, if you tween mc.y to 100 but then you advance the MovieClip timeline to a new keyframe where it was positioned at 0 in the IDE, Flash will force it back to 0. That's a Flash thing, not TweenMax. So in that case, I'd recommend either not setting up your project that way, or make sure you manually record and then set the value when you reach that keyframe. 

Hopefully something there helps :) 

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