View Full Version : DisplayObjects scaling incorrectly

Flash Gordon
01-10-2008, 07:50 AM
Attached is a sample file. The problem is the displayobject called "track_mc" traces a different width than is set by the GUI. It is off by 3 pixels!

Does anyone know what is going on here? I need to the bars to be the same width.

01-10-2008, 05:32 PM
Sprites and MovieClips automatically resize themselves based on their content. If their content changes, their width and height values change.

Flash Gordon
01-10-2008, 07:50 PM
No...I think you missed the point. If the object shows a width of 400 in the GUI it will trace 404 pixels. Here is what is happening:

For objects that have a border, the object's actionscript width (what the object.width value with trace) is equal to the object's visualWidth (what is set in the GUI) + the object scaleX. It's a bug!

Look at the attached FLA and notice the "track_mc" with set in the GUI and then notice the width that it traces. They are inconsistent and wrong. The trace value

track_mc.width = trackGUIwidth + track_mc.scaleX;

It is consistent among all objects with a border.

What I need is to be able to set the visualWidth with actionscript. Setting track to 300 pixels with actionscript will actually make it display at ~297 pixels.

Flash Gordon
01-10-2008, 08:24 PM
attached is the conversion and fix for this BUG.

* Because of a bug with how object with border widths (and heights) are measured, we must
* convert the desired display width (as it would appear in the GUI and on screen) into
* a scaled actionscript width. The actionscript width has the following equation:
* ASwidth = obj.visualWidth + obj.scaleX;
* @obj.visualWidth is the width set in the GUI
* @obj.scaleX is the scale value of the object
* @ASwidth is the width it will trace in actionscript

var visualWidth:Number = 300; // how it should look on the screen
var noScaleWidth:Number = track.width / track.scaleX - 1; // find the width without scaling as in GUI
var scale:Number = visualWidth / noScaleWidth; // find how much it needs to scale to
track.width = visualWidth + scale;

trace( track.width ); // traces 303 but visually appears as 300 pixels