AS3: MovieClip higher than set mask - actionscript-3

I have this annoying problem with masks and height om movieclips. I don't know whether it's just how Flash behaves or if I'm missing something.
I have a movieclip with a prefilled content (some simple vector graphic in a movieclip), with the height of 40. I then apply a mask to it, with the height of 30. Now i would think that the MovieClip is 30 pixel high, but it turns out to be 40 pixel high!?!
Is there some property im not setting or does the movieclip always assume the height of ALL the content within it? or what?
Actually in another clip, too, I have predefined 2 vector graphics (in two seperate movieclips), where the highest one is applied as a mask to the second graphic. The movieclip again assumes the height of the highest element. That might be logical, as it is the mask, BUT! when i then resize my mask (programatically) the height of the movieclip remains the same!?!?
Is there some way to recalculate the height of a movie clip? Or am I missing something?

You are correct that the MovieClip size is the bounding rectangle around all its content, with no consideration for which clips within could be masks.
If you want to know the size of the visible masked area, why not give the MovieClip that is the mask an instance name and use its width, height and position for your layout purposes?

Related

How to resize an empty container movieclip in AS3?

I have an empty movie clip which I have added children to via addChild. I would like to be able to scale this movie clip by half so that all it's children's dimensions are halved. Changing the height and width properties of the container doesn't work.
myclip.scaleX = myclip.scaleY = 0.5;

give a sprite its children's width

I'm trying to simulate window behavior in AS3, so I have a sprite I named "container" which contains children. One of them is a TextField, others are Sprites.
When I add the textfield in my container I'm glad to see this one's width is re-calculated. So, if my textField width is set to 50px, my container too. So my window simulation is working well.
But, when I add the others sprites, the width of my container does not change, so my window simulation is no more working well... Why is that please ? I can't find no explanation.
Thanks a lot.
This should not be a problem, as the width and height are always calculated based on the children position and sizes. This is taken from the ActionScript documentation:
DisplayObject > width:
Indicates the width of the display object, in pixels. The width is
calculated based on the bounds of the content of the display object.
When you set the width property, the scaleX property is adjusted
accordingly
There must be another problem, so maybe try posting your code, or reducing the problem down to a simple example.

Height of component increasing when adding children

I have a simple flash component that is just a rectangle with a border around it. This component represents my chat box. I then create 20 TextFields that will be overlapped on the component to display text.
The odd thing that is happening is that my components height is originally 200, but with each textfield i add as a child to the component the height data of the component increases by the height of the textfield.
Let me clarify that the height of the object in pixels is not changing, but simply the this.height of the component. I can make a static const that I can use for the original height of the component, but I find this behavior strange.
Could anyone comment on why this is happening?
Thanks!
This is expected behavior. The height property of a parent will include all of its children, same with the width property.
Any graphics drawn inside of this parent will not change, you would have to update this manually by creating a nested clip and adjusting its size.

Change width and height of container without changing child's dimension

I am having a movieclip container that needs change in it's dimensions. However it contains a bitmap, that needs to be preserved. So that it remains intact no matter how i change the dimension of it's container.
I know, that one way is to change the scale of "bitmap" accordingly. So say, container goes twice in width, then bitmap can be adjusted to scale = 0.5 ( compensating thus).
However i am doubtful, if this method would be visibly good for the bitmap, in case the dimension changes are in decimals. Like scale = 1.2345 etc
Any other good way ?
V.
You could try overriding the scaleX/scaleY setters and getters of your container, so that a change to them results in changing everything inside the container except your bitmap.
That would work, but is a bit strange. Are you sure that you can not organize your objects in a different manner?
If you have items in your container that should not be affected by the containers dimensions, then those items simply do not belong there. It would probably be a good idea to split up the structure.
You could have a Sprite that holds your Bitmap, and then apply your "container" as a mask to that, so that only a part as big as the "container" is visible, or something along those lines.
Apply a matrix to the BitmapData, which will resample it.

Flash Transparency of Overlapping Items

In Flash, I have a container with several overlapping children. When I give this container an alpha value of .5, some of the children can be seen behind others that overlap them. I would rather be able to take the whole thing as a composite image and blend it that way.
Any ideas? cacheAsBitmap on the parent container doesn't have any effect.
BlendMode.LAYER
Well, use Bitmap.draw() function... And then just alpha that image.
Like, put it into a MC and give an alpha value to it (for example).