Question
Aligning an object to the center...
I'm trying to load an image for displaying in a container
which have been loaded from the Library and placed on the stage.
Loading the image for which to use is no problem but algning it to the center of the stage is a problem.
Now, keeping in mind that loaded images usually are placed at the top-left corner of the stage I tried to solve the problem like this...:
a = stage.stageWidth/2 (finding the center of the stage)
b = image.width/2
c = a-b (giving us the result of which to place the image)
image.x = c;
The formulas above make sence... in theory. In real life (at least on my computer) it doesn't work.
Now, there might be some factors to consider when doing simple math like this...:
- Can it be that the container is not the same size as the image loaded?
- Can it be that I have to keep the x and y of the container (although I have aligned it so it's placed at the center of the stage)?
Any advice are helpfull...
Thanks in advance...
AceOfFlash
Loading the image for which to use is no problem but algning it to the center of the stage is a problem.
Now, keeping in mind that loaded images usually are placed at the top-left corner of the stage I tried to solve the problem like this...:
a = stage.stageWidth/2 (finding the center of the stage)
b = image.width/2
c = a-b (giving us the result of which to place the image)
image.x = c;
The formulas above make sence... in theory. In real life (at least on my computer) it doesn't work.
Now, there might be some factors to consider when doing simple math like this...:
- Can it be that the container is not the same size as the image loaded?
- Can it be that I have to keep the x and y of the container (although I have aligned it so it's placed at the center of the stage)?
Any advice are helpfull...
Thanks in advance...
AceOfFlash