1

This is really stumping me: I have a little app that allow the user to zoom in/out, rotate, flip horizontally and manipulate the colour of a photo. The photo is loaded via the Loader class. The app works perfectly in the dev environment however if fails once tested in the browser. I did a little debugging and I noticed a value for one of matrix calculations equates to a positive value in the dev environment but a negative value in the browser (under the exact same conditions). What am I missing here?

Here is my code for two of the functions that get called during my testing:

    function zoomOut(e:MouseEvent):void{
    matrix = imageLoader.content.transform.matrix;
    imageLoader.content.scaleY = imageLoader.content.scaleY*.90;
    imageLoader.content.scaleX = imageLoader.content.scaleX*.90;
    statusText.text = imageLoader.content.scaleY.toString();
    if(matrix.a < 0){
    matrix.a = -1*imageLoader.content.scaleY;
    matrix.tx = imageLoader.content.width;
    }else{
        matrix.a = imageLoader.content.scaleY;
    }
    matrix.d = imageLoader.content.scaleX;


matrix.transformPoint(newPoint(imageLoader.content.width/2,imageLoader.content.height/2));
        imageLoader.content.transform.matrix = matrix;
    }

        function flipHorizontal(e:MouseEvent):void {
            matrix =imageLoader.content.transform.matrix;
            matrix.transformPoint(new Point(imageLoader.content.width/2,imageLoader.content.height/2));
    if (matrix.a>0) {
    matrix.a=-1*matrix.a;
    matrix.tx=imageLoader.content.width+imageLoader.content.x;
    } else {
    matrix.a=-1*matrix.a;
    matrix.tx=imageLoader.content.x-imageLoader.content.width;
    }
    imageLoader.content.transform.matrix=matrix;
    }

From what I can tell, imageLoader.content.scaleY is equating differently in the browser environment.

Thanks so much for your help.

Jason

Jason
  • 129
  • 11

1 Answers1

2

The most likely thing is that the function operating on the loader.content is getting called before the image has completely loaded, resulting is zeroes and NaN values that mess up your processes.

Try disabling this function until after the image is loaded and the Loader.contentLoaderInfo has dispatched its COMPLETE event.

Plastic Sturgeon
  • 12,527
  • 4
  • 33
  • 47
  • Hi Plastic Sturgeon. I appreciate your help. I found where the issue lies however I don't know why. If you look at the flipHorizontal function, you'll see the line: imageLoader.content.transform.matrix = matrix; For whatever reason, this equation isn't functioning in the brower. It does however in the dev environment. Again, not sure why. Thanks. – Jason Feb 16 '12 at 15:54
  • Fixed it! Decided to simplify the zoomOut function and just use the matrix transformation to make the change: 'function zoomOut(e:MouseEvent):void{ matrix.scale(.9,.9); imageLoader.content.transform.matrix = matrix; }' Thanks again for your help. – Jason Feb 16 '12 at 18:18