Skip to main content
Inspiring
November 27, 2013
Question

Change fonts issue on runtime

  • November 27, 2013
  • 1 reply
  • 852 views

Hi

I have load system fonts and I wanna change fonts in my dynamic textbox but it dosen't work,

I take files from http://www.emanueleferonato.com/2008/05/21/create-a-font-browser-with-flash-as3/  <<< you can download source file from here

you can view my files http://www.fltech.in/fontsissue/,

here the main issue is when you change font text goes unvisible

here my code

import fl.data.DataProvider;

import flash.text.TextField;

import flash.text.TextFormat;

import flash.text.Font;

var fonts:Array = Font.enumerateFonts(true).sortOn("fontName");

var fonts_array:Array = new Array();

for (var i:int = 0; i < fonts.length; i++) {

    fonts_array.push(new String(fonts.fontName));

}

var dp:DataProvider=new DataProvider(fonts_array)

font_list.dataProvider = dp

font_list.addEventListener(Event.CHANGE, change_font);

sampletext.addEventListener(Event.CHANGE,change_text);

function change_font(event:Event):void {

    var font:TextFormat = new TextFormat();

    font.font = new String(font_list.selectedItem.data);

    displayer.setTextFormat(font);

}

function change_text(event:Event) {

    displayer.text = sampletext.text;

}

This topic has been closed for replies.

1 reply

Inspiring
November 27, 2013

apart from the fact that your app won`t work the way you intend,

since flash can`t simply access the users systemfonts and use them in a textfield:

you only have embedded a subset of chatracters in your Result field.

You have to embed every possible charcter if you want to gurantee  it displayed.

Also: The change_font event somehow seems to clear the variable which holds the sample text.

Inspiring
November 27, 2013

you mean if i embed the font then will it work..?,

Inspiring
November 27, 2013

you mean if i embed the font then will it work..?,

If you want to publish over the web, your app will not work, simply because you can`t embed every possible font every of your users might have installed.