How to adjust SWF quality with ActionScript
07 July, 2008
If you have ever tried to play an intense SWF file with a slightly slower computer, you are likely to have experienced some slow-down, or chugging, of the file. This is mostly prevalent in Flash games where many elements are being controlled on the screen, but it can also occur in complex or large animations as well.
One way to alleviate this high demand is to allow the user to adjust the quality of the SWF file. For this, we need to adjust the quality with ActionScript.
We have written this article for both ActionScript 2 and ActionScript 3, so you can pick the version most appropriate to you below, and skip straight to that section.
ActionScript 2
Setting the quality of the SWF in ActionScript 2 is quite simple. It all revolves around the single line of code: _root._quality. _root is accessing the stage level obviously, and rather than using _root as we have in this example, you can use any other method to get back to the stage level, such as this._parent or _level0.
Our _quality can be set to one of four values: "BEST", "HIGH", "MEDIUM" and "LOW".
- "BEST" is a "very high rendering quality. Graphics are anti-aliased using a 4 x 4 pixel grid and bitmaps are always smoothed."
- "HIGH" is a "high rendering quality. Graphics are anti-aliased using a 4 x 4 pixel grid, and bitmaps are smoothed if the movie is static. This is the default rendering quality setting used by Flash."
- "MEDIUM" is a "medium rendering quality. Graphics are anti-aliased using a 2 x 2 pixel grid, but bitmaps are not smoothed. This is suitable for movies that do not contain text."
- "LOW" is a "low rendering quality. Graphics are not anti-aliased, and bitmaps are not smoothed."
Text is most affected when it is set to "anti-alias for animation" as it is in the circle. The labels are set to "anti-alias for readibility" and are not affected.
You can see the difference of each rendering quality in the example below. Click each of the buttons to see how the quality is affected.
So, our code to adjust the quality in this file:
stop();
_root._quality = "BEST";
low_qual_btn.onRelease = function() {
this._parent._quality = "LOW";
}
med_qual_btn.onRelease = function() {
this._parent._quality = "MEDIUM";
}
high_qual_btn.onRelease = function() {
this._parent._quality = "HIGH";
}
best_qual_btn.onRelease = function() {
this._parent._quality = "BEST";
}
As you can see from the examples, it is not a lot of code at all to add and it can make a big difference to the usability of the SWF file. The source files for this example are available at the link below.
ActionScript 3
Setting the quality of the SWF in ActionScript 3 is quite simple. It all revolves around the single line of code: stage.quality.
Our quality can be set to one of four values: StageQuality.BEST, StageQuality.HIGH, StageQuality.MEDIUM and StageQuality.LOW.
- BEST "specifies very high rendering quality: graphics are anti-aliased using a 4 x 4 pixel grid and bitmaps are always smoothed."
- HIGH "specifies high rendering quality: graphics are anti-aliased using a 4 x 4 pixel grid, and bitmaps are smoothed if the movie is static."
- MEDIUM "specifies medium rendering quality: graphics are anti-aliased using a 2 x 2 pixel grid, but bitmaps are not smoothed."
- LOW "specifies low rendering quality: graphics are not anti-aliased, and bitmaps are not smoothed."
Text is most affected when it is set to "anti-alias for animation" as it is in the circle. The labels are set to "anti-alias for readibility" and are not affected.
You can see the difference of each rendering quality in the example below. Click each of the buttons to see how the quality is affected.
So, our code to adjust the quality in this file:
stop();
function set_quality_low(evt:MouseEvent):void {
stage.quality = StageQuality.LOW;
}
function set_quality_med(evt:MouseEvent):void {
stage.quality = StageQuality.MEDIUM;
}
function set_quality_high(evt:MouseEvent):void {
stage.quality = StageQuality.HIGH;
}
function set_quality_best(evt:MouseEvent):void {
stage.quality = StageQuality.BEST;
}
low_qual_btn.addEventListener(MouseEvent.MOUSE_UP, set_quality_low);
med_qual_btn.addEventListener(MouseEvent.MOUSE_UP, set_quality_med);
high_qual_btn.addEventListener(MouseEvent.MOUSE_UP, set_quality_high);
best_qual_btn.addEventListener(MouseEvent.MOUSE_UP, set_quality_best);
As you can see from the examples, it is not a lot of code at all to add and it can make a big difference to the usability of the SWF file. The source files for this example are available at the link below.
ferrari_chris



Dustin says:
2009-12-20 18:39:56
You should also mention that you need certain imports for AS3. Since we do not apply these to the timeline, if we're coding properly in AS3.
import flash.display.StageQuality;
Add your comment on this article below:
Sorry, there's an error with your form entries. We really appreciate your comment, so please try again.
Form submitting now...