Using embedded fonts with the ComboBox control in Flash CS3

by Peter deHaan on March 9, 2008

in ComboBox

The following example shows how you can use embedded fonts with a Flash CS3 ComboBox control’s drop down menu in ActionScript 3.0.

Full code after the jump.

// ActionScript 3.0
/**
 * Requires:
 *   - a ComboBox control in your library.
 *   - an embedded font in your library with a linkage
 *      identifier of "VerdanaEmbedded" and a normal 
 *      font weight.
 */
import fl.controls.ComboBox;
import fl.data.DataProvider;
 
var font:Font = new VerdanaEmbedded() as Font;
var tf:TextFormat = new TextFormat();
tf.font = font.fontName;
 
var arr:Array = new Array();
arr.push({label:"One"});
arr.push({label:"Two"});
arr.push({label:"Three"});
arr.push({label:"Four"});
arr.push({label:"Five"});
arr.push({label:"Six"});
 
var cb:ComboBox = new ComboBox();
cb.dropdown.setRendererStyle("embedFonts", true);
cb.dropdown.setRendererStyle("textFormat", tf);
cb.dataProvider = new DataProvider(arr);
cb.move(10, 10);
addChild(cb);

If you wanted to use an embedded font for the main text field portion of the ComboBox control as well, you could use the following snippet:

// ActionScript 3.0
var cb:ComboBox = new ComboBox();
// embed fonts in main text field
cb.textField.setStyle("embedFonts", true);
cb.textField.setStyle("textFormat", tf);
// embed fonts in dropdown menu
cb.dropdown.setRendererStyle("embedFonts", true);
cb.dropdown.setRendererStyle("textFormat", tf);
cb.dataProvider = new DataProvider(arr);
cb.move(10, 10);
addChild(cb);

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: