Prevent Scaling With ActionScript 3
Posted on | March 28, 2012 | No Comments
So you have a flash application that looks great in a webpage, but when you view the .swf file directly in the browser it stretches and distorts and looks plain ugly. Fortunately, there is a solution!
Solution
By default your flash application will attempt to fill the container it is in, regardless of the width and height settings you have set. It is possible to tell your application ‘Oi! NO!’ by adding this line into your script:
[javascript]
stage.scaleMode = StageScaleMode.NO_SCALE;
[/javascript]
If you are including this in a .as file then you will also need to include StageScaleMode:
[javascript]
import flash.display.StageScaleMode;
[/javascript]
Examples
Here are a couple of examples. The first one does not have stage.scaleMode line of code, while the second does. These are direct links to the .swf files so will both fill the width and height of the browser you are viewing them with.
Without the fix
With scaleMode set
As you can see, the image in the first one has been stretched with the .swf file.
The second one, the one with scaleMode set, shows the image at the correct size, without any scaling what so ever.
Posted By:Richard Parnaby-King