How to stop children adding to their parent's size? - actionscript-3

in my game I have a solar system with many bodies, they're all the same class/movie clip and their size is determined by their mass. When assigned a target that target becomes a child of the body. The body moves towards the target and the target is removed when reached.
This approach is essential as it means waypoints can be set and the targets can orbit the solar system: because everything around the target is moving it also needs to move to keep relative motion otherwise you'd end up in the wrong place.
The problem is having the target a long distance away makes the body's bounding box huge and the body is shrunk down to fit the required dimensions. What I need is to make the target's position not affect the body's size but I can't find the required method/property and visible = false isn't doing the trick. If anybody has a solution that's be great.

I believe includeInLayout may help you with this. visible=false will not display the object, but it's still used in the layout calculations. includeInLayout=false will remove the object from the layout calculations.

Related

Prevent a specific matlab gui pushbutton to change size when display settings are changed in windows

I create a pushbutton to put a gif as my program is loading. The button must have a static size in order to assure that the entire gif fits, but the borders of the button behind does not show. I have tried getting rid of the borders and I have tried using something other than a pushbutton. Nothing seems to work.
Below is an example code of what I have done:
pos = [3, 4, 50, 40];
gif = sprintf('<html><img src="file:/%s\\myGif.gif"/></html>',pwd);
ld = uicontrol('style','push', 'BackgroundColor', 'w', 'ForegroundColor',...
'w', 'pos', pos, 'String',gif,'enable','inactive','CData',uint8(240*ones(18,18,3)));
The figure, axes, uicontrols, etc. have Units property which can be set to inches, centimeters, points, pixels, characters and normalized.
For example let's have figure and one push button in it.
fig=figure();
pb =uicontrol('style','pushbutton','string','Push','parent',fig);
When the Units property is set to any value but normalized, the values of position and outerposition properties are bound to bottom-left corner of the parent entity (say fig handle is a parent of pb) and the length of the unit (say set(pb,'units','inches')). In that case when parent(fig) is moved and/or resized, the child position will remain same to the bottom-left corner and its size won't be changed (since it is bound to absolute value)
When the Units is set to normalized (say set(pb,'units','normalized')) the position and outerposition properties are bound to bottom-left corner and the size of the parent. In that case when the parent (fig) is resized, position of child will remain in same relative position to the parent frame and so does the size of the child (since it is bound to parent dimensions).
This behaviour is independent on the parents units property.
If the location of the child - first two elements of (outer)position - is wanted to be relative to the parent dimensions but the size of the child - last two elements of (outer)position - is wanted to be constant the resolution is less straightforward. Typical case is when controls are on the right side of the figure.
When the user is responsible for the resize one can use ResizeFcn property and create routine that will change appropriate properties of the children.
When the code is responsible for the resize one can read the position properties before the command possibly leading to the resize action and then re-set those values to fit one's needs.

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.

Relative positions inside a div. Weird interactions

I am trying to replicate a Udacity question in html. The original question is here. (*)
My example is here. As you can see(**), the only problem is the positions of the radio buttons(***). I've seen the positions using gimp, and tried to use those into the html. However, not only there is an offset (which is perfectly managable in itself) but also this offset varies from button to button. Even worse: there seems to be some kind of interaction: removing some buttons makes the rest get closer to where they should be.
I (suppose) I could just guess positions till I got it right, but as I will probably do this many times, I'd rather understand the problem better. What is going on ? Is there a better way to achieve the same result ?
(*) I've already been given the suggestion to look at the source, and tried to, not with much sucess
(**) I opened the file on firefox 14 and chromium 18
(***) they were meant to be on north, west, east and on the square just below west
Relative positioning is not what you want. Relative means offset the element from its nominal position, but then treat it just as if it were in its original position with regard to how it affects subsequent elements in the flow.
What you actually want is absolute positioning. First, you need to apply relative or absolute positioning to the container (the graph div), and then any absolute positioning you apply to the contents will be with respect to that container.
This terminology is a bit confusing, of course, since absolute positions are actually relative to a container.

I think CSS3 transform translateZ is equal to scale by some means

In some case, I think the translateZ and scale have the same effect ,just like zoom in or zoom out.
I think there are some calculate connection between them, if I konw one value of them, like translateZ(-1000px) and the parent perspective value, can I calculate the scale value that have the same effect equal to the translateZ ?
You are correct. As an object moves towards you (i.e. translateZ) it appears larger (i.e. scale).
As shown in this diagram, perspective defines where the viewer is relative to the container and translateZ defines where the subject is relative to the container.
The formula to go from scale to translateZ (and back):
-OR-
I'll leave the mathematical proof to a math whiz, but I did some checking with the pythagorean theorem and everything works out.
Example:
Let's say you're 100px from the container: #container { perspective: 100px; }
If you translateZ(50px), the subject has moved halfway to you and will appear twice as large, making it 2x.
If you translateZ(75px), the subject has moved another halfway closer and will double again, making it 4x.
If you keep doing this, as you get closer to translateZ(100px), the subject will approach being to infinitely large.
Try it out. Here's a JSFiddle to compare different examples visually.
Limits:
This works if the subject is moving directly towards you, but falls apart if you do things like rotate the subject in 3D space. There is math for that too, but it gets complicated. Check out 3D Projection on wikipedia.

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.