views:

153

answers:

1

I have write a simple example that adds a canvas and draw a rectangle with stroke size 20 scale mode none.

The problem is that if I call getBounds() first time I will get a correct result but after I call scale(); the getBounds() function will give me a wrong result.

It will take in cosideration the stroke but stroke has scalemode to none and on the screen nothing happens but in the result I will have a x value smaller. Can sombody tell me how can I fix this ?

   protected var display :Canvas;

    protected function addCanvas():void
    {            
        display = new Canvas();
        display.x = display.y = 50;
        display.width = 100;
        display.height = 100;

        display.graphics.clear();
        display.graphics.lineStyle( 20, 0x000000, 0.5, true, LineScaleMode.NONE );
        display.graphics.beginFill( 0xff0000, 1 );
        display.graphics.drawRect(0, 0, 100, 100);
        display.graphics.endFill();

        area.addChild( display );
        traceBounce();
    }

    protected function scale():void
    {
        var m :Matrix = display.transform.matrix;
        var apply :Matrix = new Matrix();
        apply.scale( 2, 1 );
        apply.concat( m );

        display.transform.matrix = apply;
        traceBounce();
    }

    protected function traceBounce():void
    {
        trace( display.getBounds( this ) );
    }
A: 

Setting the width/height and scaling the same display object can give confusing results. Does your Canvas class do anything unusual (e.g. set the scrollRect or add a mask)?

Also you could try getting bounds of the Canvas' parent instead, or setting cacheAsBitmap on the Canvas and seeing if that helps?

RandomEtc
The example is very simple if you put a canvas for example at 20,20 with a border and start scale the X position of the canvas will not be the same if you trace getBounds but with getRect for example you will see the same result check my sample and add this:<mx:Button click="addCanvas()" label="add" /><mx:Button click="scale()" label="scale" /><mx:Canvas id="area" cacheAsBitmap="true" />
ghalex