package {
import com.adobe.viewsource.ViewSource;
import fl.events.ColorPickerEvent;
import fl.events.ComponentEvent;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFormat;
/**
* Example application to show how embedded fonts will conflict with SWC's which include
* the same font in either static or dynamic (embed) format.
*
* @author Chris Black
*
*/
[SWF(width='300', height='300', backgroundColor='#FFFFFF', frameRate='30')]
public class ConflictingFonts extends Sprite
{
[Embed(source="/assets/fonts/georgia.ttf", advancedAntiAliasing="true", fontFamily="Georgia",
fontName="Georgia", fontWeight="normal", mimeType="application/x-font" )]
private var GeorgiaFont:Class;
public static const GEORGIA:String = "Georgia";
[Embed(source="/assets/fonts/georgia.ttf", advancedAntiAliasing="true", fontFamily="MyGeorgia",
fontName="MyGeorgia", fontWeight="normal", mimeType="application/x-font" )]
private var MyGeorgiaFont:Class;
public static const MY_GEORGIA:String = "MyGeorgia";
private var georgiaFormat:TextFormat;
private var myGeorgiaFormat:TextFormat;
private var currentFormat:TextFormat;
private var georgiaText:TextField;
/**
* Creates a new ConflictingFonts instance.
*
*/
public function ConflictingFonts()
{
ViewSource.addMenuItem(this, "http://www.blackcj.com/blog/wp-content/swfs/ConflictingFonts/srcview/index.html");
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
var cc:ColorComponent = new ColorComponent();
cc.colorPicker.addEventListener(ColorPickerEvent.CHANGE, selectColor, false, 0, true);
cc.y = 30;
this.addChild(cc);
var sc:SelectionComponent = new SelectionComponent();
sc.georgia.addEventListener(ComponentEvent.BUTTON_DOWN, selectGeorgia, false, 0, true);
sc.georgia.selected = true;
sc.myGeorgia.addEventListener(ComponentEvent.BUTTON_DOWN, selectMyGeorgia, false, 0, true);
sc.y = cc.y + cc.height;
this.addChild(sc);
georgiaFormat = new TextFormat(GEORGIA, 18);
currentFormat = georgiaFormat;
myGeorgiaFormat = new TextFormat(MY_GEORGIA, 18);
georgiaText = new TextField();
georgiaText.x = 2;
georgiaText.y = 2;
georgiaText.embedFonts = true;
georgiaText.antiAliasType = AntiAliasType.ADVANCED;
georgiaText.width = 300;
georgiaText.height = 22;
georgiaText.defaultTextFormat = georgiaFormat;
georgiaText.setTextFormat(georgiaFormat);
georgiaText.text = "Invisible Text!";
this.addChild(georgiaText);
}
/**
* Used to change the color of the text. Why not have the component do something?
*
* @param event
*
*/
private function selectColor(event:ColorPickerEvent):void
{
georgiaFormat.color = event.color;
myGeorgiaFormat.color = event.color;
updateFormat();
}
/**
* Used to update the TextFormat of the TextField after a change has been made.
*
*/
private function updateFormat():void
{
georgiaText.defaultTextFormat = currentFormat;
georgiaText.setTextFormat(currentFormat);
}
/**
* Triggered when the Georgia radio button is clicked.
*
* @param event
*
*/
private function selectGeorgia(event:ComponentEvent):void
{
currentFormat = georgiaFormat;
updateFormat();
}
/**
* Triggered when the MyGeorgia radio button is clicked.
*
* @param event
*
*/
private function selectMyGeorgia(event:ComponentEvent):void
{
currentFormat = myGeorgiaFormat;
updateFormat();
}
}
}