ComboBox Designed with Embedded Font
The ComboBox above was created in Flash CS3, and the text styles were modified using ActionScript 3.0. By extending the ComboBox class, I created a custom DesignComboBox class, then added the CBDesignRenderer class to style the dropdown fields.
The ComboBox component needs to exist in the library before you can create it with AS3. The DesignComboBox class and CBDesignRenderer class are listed below.
You can DM me on Twitter @jazzairtech if you want me to send you the FLA and AS files.
/* DesignComboBox.as */
package com.jazzairtech.ComboBoxDesign
{
import flash.text.TextFormat;
import fl.controls.ComboBox;
import fl.controls.List;
/**
* DesignComboBox class
* Apply embedded font to ComboBox List items
*/
public class DesignComboBox extends ComboBox {
private var cdDesignFmt:TextFormat;
public function DesignComboBox() {
super();
var cbFmt:TextFormat = new TextFormat();
var myArial:Arial = new Arial();
cbFmt.font = myArial.fontName;
cbFmt.size = 20;
textField.setStyle("embedFonts", true);
textField.setStyle("textFormat", cbFmt);
// Apply CBDesignRenderer to set dropdown format
dropdown.setStyle("cellRenderer", CBDesignRenderer);
}
override protected function drawLayout():void {
super.drawLayout();
textField.y = 0;
}
}
}
/* CBDesignRenderer.as */
package com.jazzairtech.ComboBoxDesign
{
import flash.text.TextFormat;
import fl.controls.listClasses.CellRenderer;
/**
* CBDesignRenderer class
* Adds an embedded font (Arial) to ComboBox List items
*/
public class CBDesignRenderer extends CellRenderer {
public function CBDesignRenderer() {
super();
var cbFmt:TextFormat = new TextFormat();
var myArial:Arial = new Arial();
cbFmt.font = myArial.fontName;
cbFmt.size = 16;
this.setStyle("embedFonts", true);
this.setStyle("textFormat", cbFmt);
}
}
}
Styling the ComboBox with AS3 takes a little extra coding, but I think it's worth the effort to improve how it looks.
Aloha, Joe
can I change any specific text color?
ReplyDelete@Arindam you should be able to change the font color by adding a color value to the TextFormat. For example,
ReplyDeletecbFmt.color = 0x0000FF;
will display blue text in the ComboBox.
can you change just a single item in the list to be bold?
ReplyDelete@jallen It's been a while since I tried, but I think the font style of a single list item can be set to bold. Allow me some time and I'll get back to you on this.
ReplyDelete