Hi all,
I've been working on a zoom effect to a map in my project. I got it from a file originally published on http://gasi.ch/blog/2008/02/05/zooming-in-flash-flex/
Its been working like a charm, but now when i try to add a TweenMax, im finding it very difficult to implement it right.
My original zoom code:
public function scaleAt( scale : Number, originX : Number, originY : Number ) : void
{
// get the transformation matrix of this object
affineTransform = _myObject.transform.matrix
affineTransform.translate( -originX, -originY )
// move the object to (0/0) relative to the origin
affineTransform.translate( -originX, -originY )
// scale
affineTransform.scale( scale, scale )
// move the object back to its original position
affineTransform.translate( originX, originY )
// apply the new transformation to the object
_myObject.transform.matrix = affineTransform
}
// Event Handlers
public function onMouseWheel( event : MouseEvent ) : void
{
// set the origin of the transformation
// to the current position of the mouse
var originX : Number = stage.mouseX
var originY : Number = stage.mouseY
// zoom
if( !event.altKey )
{
if( event.delta > 0 )
{
// zoom in
scaleAt( 9/8, originX, originY )
}
else
{
// zoom out
scaleAt( 8/9, originX, originY )
}
}
}
This works fine, except it needs a tween. Now when i try to do this:
affineTransform = _messeHolder.transform.matrix
affineTransform.translate( -originX, -originY )
TweenMax.to(affineTransform, 1, { onUpdate:applyMatrix, onUpdateParams:[_myObject, affineTransform]});
function applyMatrix($clip:Sprite, $matrix:Matrix):void {
$matrix.a *= scale;
$matrix.d *= scale;
$matrix.tx *= scale;
$matrix.ty *= scale;
$matrix.tx += originX;
$matrix.ty += originY;
$clip.transform.matrix = $matrix;
}
It reacts very wrong. I've played around with the values, and tried to place all the values in the TweenMax.To line, but without luck. Im guessing the problem has something to do with the matrix calculating the mouse properties?
Thanks in advance! Any help appreciated!! Ive been sitting with this way too long
Cheers
Steffen