PDA

View Full Version : An extremely difficult problem (for flex)


corn flex
08-14-2008, 01:10 PM
I have two images (SWFLoaders actually). The second one is smaller than the first and I want the second one to be visually centered in front of the first image.

Sounds simple? Maybe in other programming environments.

Here was my initial (obvious) solution:

img[n].x += (img[n-1].width-img[n].width)/2;
img[n].y -= (img[n-1].height-img[n].height)/2;

(where img[n] and img[n-1] are initially at the same location).

The centering is off by as much as 2. Off by one you could understand, by why should it be off by 2. And the error is not at all predictable either.

I've tried various combinations of round, ceil, floor, content.width, and so on.

The problem also is contingent on whether the image is an SWF, .JPG etc.

corn flex
08-14-2008, 01:32 PM
Nevermind.

The problem was assuming they were at the same location to start with.
A previous calculation put them at slightly different locations.