views:

41

answers:

1

I am working on an application that will allow a user to scale an image. The issue that I am having with the method below is that the scaling is always taking place on the previous scale point.

For example: If I scale the image up one and then scale the image down one. I have to scale down twice to get it back to the point I want it to be.

Any help with this is greatly appreciated.

Here is my current code:

private var sourceBMD:BitmapData = testImage.source as BitmapData
private var matrixScaleX:Number  = 1;
private var matrixScaleY:Number  = 1;
private var baseScaleX:Number  = .05;
private var baseScaleY:Number = .05;

    private function sourceZoom(zoomType:Boolean = false):void{
        var matrix:Matrix = new Matrix();
        var matriximage:BitmapData;


        if(zoomType){
            matrixScaleX = matrixScaleX + baseScaleX;
            matrixScaleY = matrixScaleY + baseScaleY;
            matrix.a = matrixScaleX;
            matrix.d = matrixScaleY 
        }else{
            matrixScaleX = matrixScaleX - baseScaleX;
            matrixScaleY = matrixScaleY - baseScaleY;
            matrix.a = matrixScaleX;
            matrix.d = matrixScaleY;    
        }


        matriximage = new BitmapData(sourceBMD.width, sourceBMD.height, false, 0x0000000);

        trace('MatrixScaleX: ' + matrixScaleX);
        trace('MatrixScaleY: ' + matrixScaleY);
        trace('BaseScaleX: ' + baseScaleX);
        trace('BaseScaleY: ' + baseScaleY);
        trace('Matrix: ' + ObjectUtil.toString(matrix));

        matriximage.draw(sourceBMD, matrix);                
        testImage.source =  matriximage;    

    }
+1  A: 

That looks fine, I'd suspect that the problem lies with your input or the place this is getting called.

In order for it to work, events need to happen like this in your code:

capture input -> scale image -> draw image.

Since you appear to be setting the image to draw at the end of this function, I would check that this function is being called after the input has finished processing.

Can you confirm that's what's happening?

Ipsquiggle
The input is happening from a button. I can confirm that the issue is not with the click event.
Tempname
What I mean is this: If you are setting the input from a `CLICK`, and resizing the clip on a `ENTER_FRAME` event, there is no guarantee that the click runs before the enter frame. Try putting a trace at the top of this function, and a trace on your button, and see what order they are running in.
Ipsquiggle