Hi All,
I have created a class that creates a button with a bitmap underneath, and dynamic embedded text on the top. The buttons upState has a drop shadow on it, the overState, changes the Text from a dark to a light color, and the down moves the buttons image and text by a couple of pixels down and across.
All this works fine, however when I click on the button, I get a very quick flicker of my text field, which was not my intention. I have already tried changing the AntiAliasType from Normal to Advanced, and also tried to caching each button state as a bitmap - however neither of these actions has stopped the flicker. If the button color is set the same for all states of the button, my flicker goes away, so I suspect the problem is something to do with the text color changing.
I am a complete newbie to Action Script, and can not find any solution to this unwanted flicker. Any suggestions would be very gratefully received. My Class is as follows:
ActionScript Code:
package Classes {
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.DropShadowFilter;
import flash.text.*;
public class CreateButton extends SimpleButton {
private var _btnName:String;
private var _btnGraphic:BitmapData;
private var _btnBitmapDown:Bitmap;
private var _btnBitmapUp:Bitmap;
private var _btnBitmapOver:Bitmap;
private var _btnBitmapHit:Bitmap;
private var _btnFont:Font;
private var _btnFontSize:uint;
private var _btnDownCol:uint;
private var _btnUpCol:uint;
private var _btnOverCol:uint;
public function CreateButton(btnName:String, btnGraphic:BitmapData, btnFont:Font, btnFontSize:uint = 35,
btnUpCol:uint = 0xFF2E0E03,
btnDownCol:uint = 0xFFE6E4DE,
btnOverCol:uint = 0xFFE6E4DE) {
_btnName = btnName;
_btnGraphic = btnGraphic;
_btnBitmapDown = new Bitmap(_btnGraphic);
_btnBitmapUp = new Bitmap(_btnGraphic);
_btnBitmapOver = new Bitmap(_btnGraphic);
_btnBitmapHit = new Bitmap(_btnGraphic);
_btnFont = btnFont;
_btnFontSize = btnFontSize;
_btnDownCol = btnDownCol;
_btnUpCol = btnUpCol;
_btnOverCol = btnOverCol;
this.downState = createGraphic(_btnBitmapDown, 2, 2, _btnDownCol);
this.upState = createGraphic(_btnBitmapUp, 0, 0, _btnUpCol);
this.overState = createGraphic(_btnBitmapOver, 0, 0, _btnOverCol);
this.hitTestState = createGraphic(_btnBitmapHit, 0, 0, _btnDownCol);
//this.hitTestState = this.upState;
}
private function createGraphic(btnBitmap:Bitmap, Xoffset:int, Yoffset:int, btnCol:uint):Sprite {
var btnSprite:Sprite = new Sprite();
var btnFormat:TextFormat = new TextFormat();
var btnLabel:TextField = new TextField();
btnFormat.font = _btnFont.fontName;
btnFormat.size = _btnFontSize;
btnFormat.align = TextFormatAlign.CENTER;
btnFormat.color = btnCol;
btnLabel.autoSize = TextFieldAutoSize.CENTER;
btnLabel.defaultTextFormat = btnFormat;
btnLabel.embedFonts = true;
btnLabel.text = _btnName;
btnLabel.cacheAsBitmap = true;
btnLabel.x = Math.ceil((_btnGraphic.width - btnLabel.width)/2);
btnLabel.y = Math.ceil((_btnGraphic.height - btnLabel.height)/2);
btnSprite.addChild(btnBitmap);
btnSprite.addChild(btnLabel);
btnSprite.x = Xoffset;
btnSprite.y = Yoffset;
if (Xoffset == 0) {
var btnShadow:DropShadowFilter = new DropShadowFilter();
btnShadow.distance = 3;
btnShadow.blurX = 10;
btnShadow.blurY = 10;
btnShadow.alpha = .6;
btnShadow.angle = 30;
btnSprite.filters = [btnShadow];
}
btnSprite.cacheAsBitmap;
return btnSprite;
}
}
}
Thanks in advance for any help.