Jason
Jason

Reputation: 129

Actionscript math calculation behaving differently in browser

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

Upvotes: 1

Views: 107

Answers (1)

Plastic Sturgeon
Plastic Sturgeon

Reputation: 12527

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.

Upvotes: 2

Related Questions