Domanda

I have a skinnable container scaled to 0.5 in both axis i.e scaleX = 0.5 and scaleY = 0.5, as per flex scaling if i scale a container then corresponding child Elements are also get scaled as well, but i need to prevent one of the children of that container from scaling down. I tried something like this

    public static function preventScaleForComponent(target:UIComponent):void
    {
        if(!target)
            return;

        var parent:DisplayObjectContainer = target.owner;
        if(parent)
        {
            trace("Target ScaleX :: "+target.scaleX+"Target ScaleY :: "+target.scaleY);
            trace("Parent ScaleX :: "+parent.scaleX+"Parent ScaleY :: "+parent.scaleY);

            target.scaleX = 1 + parent.scaleX;
            target.scaleY = 1 + parent.scaleY;
        }
    }

but i don't know is this the right way or can we do by any other means. With this if my parent container is scaled to 0.5 then the child scale value will be 1.5, so that it looks same as how it looks normally without scaling.

È stato utile?

Soluzione

I think you're on the right track but your sum is wrong, to get a child component to retain its original size:

target.scaleX = 1/parent.scaleX;

This way if parent scale is 2 (twice the normal size) the target/child scale will be 0.5 (half its original size), and in the context of its parent, its original size.

Remember that scale is a multiplier applied to an absolute dimension (width/height), not a measurement in itself - when you double the parent, you must halve the child, and vice versa, not simply add the number taken from one to the other etc

Hope this helps!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top