1
votes

I have created a custom component - MyImage - that has two children including a Bitmap as well as a Sprite.

My display object hierarchy is as follows -

mx:Canvas
  view:MyImage
     mx:Bitmap
     my:Sprite

If I change the MyImage.scaleX, scaleY property, the children scale as I would expect them to.

However when I try to place the children in the center using placeAgain() on getting a resize event:

    public function placeAgain():void
    {
        if (image==null) return;

        var pCanvas:Canvas = this.parent as Canvas;
        if (image.width <= pCanvas.width)
        {
            pCanvas.horizontalScrollPolicy="off";
            image.x = (pCanvas.width -image.width)/2;
        }
        else
        {
            pCanvas.horizontalScrollPolicy="on";
            image.x=0;
        }
        if (image.height <= pCanvas.height)
        {
            pCanvas.verticalScrollPolicy="off";
            image.y = (pCanvas.height -image.height)/2;
        }
        else
        {
            pCanvas.verticalScrollPolicy="on";
            image.y=0;
        }
        alignKids();
    }

I find the image.height & width have not changed despite the image getting scaled!

Isn't the child supposed to have its bounds changed after scaling its parent ? Especially after the child has actually been scaled correctly ? Why are bounds of the child stuck at the same value as before scaling? I am not caching the Bitmap, have not turned on caching of bitmaps.

1
Do I need to manually recurse through all the children and their children, look for display objects and manually update their width/height/x/y ? - TBD
This is how I'd expect it to work. I thought scale was, essentially, a zoom in/out. It doesn't change the coordinate system of the component or the size of a component or component's children. It only changes their perceived size. - JeffryHouser

1 Answers

0
votes

Let's see...

  1. No
  2. Still no
  3. In short, to make your job as a developer easier, because you don't have to go through all the children and re-adjust their width/height/x/y (thus answering your 4th question too). You use some fixed values, apply a scaling on the parent and bam!, the rest flash takes care of the rest.

Also this would be one of those things you could have tried yourself before asking, as the setup was already there...