views:

135

answers:

2

Example:

var circle1 :Canvas = new Canvas();
var circle2 :Canvas = new Canvas();

circle1.addChild( circle2 )
circle1.scaleX = 2;

After the example before when Flash will render circle2 because it is child to circle1 it will be scaled to. Is there a way I can scale circle1 without affect circle2 or what can I do to circle2 so it can have the same scale ?

+2  A: 

It's quite simple, just compensate for the fact you double the size of the parent.

var circle1 :Canvas = new Canvas();
var circle2 :Canvas = new Canvas();

circle1.addChild( circle2 )
circle1.scaleX = 2;
circle2.scaleX = .5; // Added

A maybe handy function, which takes care of scaling issues, could be:

function setParentOnlyScaleX(parent:Canvas, scale:Number):void {
    parent.scaleX = scale;
    for (var i = 0; i < parent.numChildren - 1; ++i) {
        var child:Canvas = circle1.getChildAt(i);
        child.scaleX  = 1 / scale;
    }
}

The first snippet then would be:

var circle1 :Canvas = new Canvas();
var circle2 :Canvas = new Canvas();

circle1.addChild( circle2 )
setParentOnlyScale(circle1, 2);
Dykam
The problem here is that I do the scale on MOUSE_MOVE event. So if I change the child scale with the parent scale on every mouse move it will have wrong value. Maybe if I can catch an event before RENDER change the child matrix and after the RENDER change it back. Is there an event after RENDER is complete ?
ghalex
I fixed the code. But what do you mean with having the wrong value? This way the child sprite will always have the same size.
Dykam
+1  A: 

May help you : http://natejc.com/blog/?p=68

PeZ
Ye thx., your link and this link: http://codevil.in/?p=63 helped me.
ghalex