MovieClip resizes, but its children's height and width are not changed?
Asked Answered
B

3

6

Changing the width and height of the parent MovieClip does not bring change in the width and height of the inner MovieClip. The parent MovieClip is placed at Stage and is resized manually. When I assign the dimension of the parent MovieClip to the inner MovieClip through code, the parent MovieClip dimension is changed. I want both MovieClip to be of same width and height at runtime. However, parent MovieClip dimension is changed at design time by me.

Example:

There are two MovieClip, one inside another. Now parent MovieClip is placed at Stage at design time and its dimension is (50,50) and the child MovieClip which is inside the parent MovieClip has also same dimensions (50,50). Now, I manually change the parent MovieClip dimension by pressing Q and stretching it with mouse, the dimension of the parent MovieClip is now (100,150) or whatever I like. Now double-click on parent MovieClip and check that inner MovieClip dimension remains same i.e. (50,50)
Now in AS3 code, I change the width and height of inner MovieClip like this:

saveheight = parentmc.height;
savewidth  = parentmc.width;

now I change the child MovieClip according to the dimensions of the parent MovieClip like this:

parentmc.inner_mc.width = parentmc.width;
parentmc.inner_mc.height = parentmc.height;

but this brings change in parentmc also so I reassign value to parentmc like this:

parentmc.height = saveheight;
parentmc.width = savewidth;

In above case, parentmc and inne_rmc dimension should be same i.e (100 ,150). With swapping the values as above, I get parentmc and inner_mc to be of same dimension, but object size is never (100, 150), I have checked it with pixel-perfect air app.

Bun answered 27/2, 2011 at 20:19 Comment(0)
B
3

In your code, you are neglecting to account for the transformation to the parent that you did with the 'Q' tool in the authoring environment. The childmc's width and height are expressed in terms of parentmc's transformed coordinate space. If you wish to scale the inner clip to a specific size in stage coordinate space you need to account for the scale of the parent that resulted from your transform:

   parentmc.inner_mc.width = parentmc.width/parentmc.scaleX;
   parentmc.inner_mc.height= parentmc.height/parentmc.scaleY;

Also, if the clips aren't aligned (e.g. registered by their upper left corner and with the child at 0,0), enlarging the child could push out the boundaries of the parent.

You can also use the parent's transform matrix if you prefer that over using scaleX and scaleY.

UPDATE 4.8.11: Were you perhaps asking to do this (runtime removal of the authoring-time transform)?

saveheight = parentmc.height;
savewidth  = parentmc.width;

parentmc.scaleX = 1.0;  // Undo authoring-time scale transform
parentmc.scaleY = 1.0;  // Undo authoring-time scale transform

parentmc.inner_mc.width = savewidth;
parentmc.inner_mc.height = saveheight;

parentmc.width = savewidth;
parentmc.height = saveheight;

Note: I'm not at a computer set up with Flash to test this, so please leave me a comment if this does not do what you are expecting, and I will happily check my work and follow up.

Bose answered 6/4, 2011 at 21:4 Comment(5)
@Adam, i want inner_mc to be of same width and height but this is not happening with your code.Bun
If you want the parent clip and inner clip to both report the same width and height, and to be visually the same dimensions (i.e. inner clip filling outer), then you have no choice but to remove the transform on the parent clip by first setting its scaleX and scaleY to 1.0, effectively undoing the transform you did in the authoring environment. I will update my answer to show what this would look like.Bose
@Adam, thanks again for clearing me and firstly understanding my point. yes i want both to be same after transformation applied on parent. now, u cleared me that it is not possible unless i remove transform from parent container. Thanks alot. i was searching it for week.Bun
@Adam, the above code works fine but the thing i was looking for is impossible as after applying transform to parent, inner object can not be resized to its parent dimension. so the better option is to resize the inner object.Bun
That is correct. Transform of a parent is applied to all children, so if the parent is at 200% say, and you then set the child width and height to match the parent's width and height (which are in stage coordinate space), then you end up inflating the size of the parent by a factor of two, because a DisplayObjectContainer automatically increases its bounding box to the size necessary to visually contain all its children. The only way for parent and child to be equal in size is for the parent to have scale of 100% (1.0)Bose
V
0

it doesn't quite work like that,

you need to multiply the children by the scale of the parent.

the other thing you can do is use getBounds and then you can get the bounding rectangle of any child (and child's children etc) relative to the parent

Venturous answered 27/2, 2011 at 21:43 Comment(1)
i just want that any child added in a movieclip, must be of the same dimension, no matter how much inner child is scaled. Child can be dynamic of any size, bigger than Parent container or can be smaller than Parent container but it should be resized to parent container dimension. how would i achieve this??Bun
S
0

I honestly don't understand what you're asking, because what you describe should work!

If we have a parentMC and a childMC both with a 50 height and 50 width, if you change the parentMC.scaleX = 2; it will apear to be 100 in width. The same goes for the childMC.

Could you please provide an example of what you're trying to do here? - or some code.

Stheno answered 6/4, 2011 at 16:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.