Hi everybody.
I'm trying to use this amazing tweening class on a project I started. I'm a newbie in actionscripting but I managed to import a class and get the thing running. But I ran into a "little" problem.
My tween is happening when a user MOUSE_SCROLLs over an object which is a map with the size of the stage. Now since the initial x and y values are set to 0 (maps registration point is top left), when a user scrolls up, map should zoom in, which means that the new x and y values are less than 0. All of this worked before I tried to use the TweenMax. What TweenMax does is, it changes the new x and y values to 0, so on every zoom-in the map zooms from the top left corner. Originally, I made it zoom in depending on the mouse position (this worked before implementing TweenMax). It seems that TweenMax does not allow negative values for x and y properties. Or am I wrong?
Here is my code. I hope that somebody will be able to help me.
public function zoom (e:MouseEvent):void
{
removeEventListener (MouseEvent.MOUSE_WHEEL, zoom);
if (stage.mouseX < stageWidth && stage.mouseY < stageHeight)
{
var mod:Number = 5;
if ((scale + (e.delta / mod)) >= 1) //if the scale is bigger than 1 - zoom in ---- prevents to zoom out further than original size
{
var originX:Number = (diffX+mouseX) / scale;
var originY:Number = (diffY+mouseY) / scale;
scale = scale+(e.delta / mod);
var newX:Number = validateX(mouseX - (originX * scale)); //calculates and validates new X position (it's always a negative value when zooming in)
var newY:Number = validateY(mouseY - (originY * scale)); //calculates and validates new Y position (it's always a negative value when zooming in)
TweenMax.to(karta, 1, {x:newX, y:newY, scaleX:scale, scaleY:scale, ease:Expo.easeOut, onComplete:tweenMap}); //sets x and y to 0 !!!
diffX = Math.abs(newX);
diffY = Math.abs(newY);
}
else
{
scale = 1;
karta.x = 0;
karta.y = 0;
diffX = 0;
diffY = 0;
karta.scaleX = 1;
karta.scaleY = 1;
addEventListener (MouseEvent.MOUSE_WHEEL, zoom);
}
}
}
private function tweenMap():void {
addEventListener (MouseEvent.MOUSE_WHEEL, zoom);
}
Please help!!!