fcOnTheWeb Logo Web technologies, made easy.

fcOnTheWeb Red DotHow to adjust SWF quality with ActionScript

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".

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.

quality_as2.zip

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.

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.

quality_as3.zip

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...

Name:

Website:

Email address (not displayed):

Enter your comment below: