Pete
Pete

Reputation: 3

Flash AS3 ReferenceError: Error #1056: Cannot create property font on flash.text.TextField

First let me warn you that I’m “old school” i.e. code is on my timeline and the only classes used were those automatically created when I added several new fonts to Script1.swf which is my movieclip for embedded fonts.

On the first frame of my main movieclip which is named Round.fla, I have loaded Script1.swf that contains the fonts using the loader object. I'm using a trace statement that shows that Script1_lb.swf is loaded.

I am using a listbox (script1_lb) with movieclip icons (jpg picture of the sample font) and the data is the name of the font class, like this:

script1_lb.dataProvider.addItem( {icon:akaDora_mc, data:"akaDora"} );

I want to apply the font to a text field (design_mc.info_txt) that already exists on the stage so this is the code I used:

import flash.text.Font;
import flash.text.TextField;
var tff:TextFormat = new TextFormat();
var font:Font=new Font();

script1_lb.addEventListener(Event.CHANGE,getFont);

function getFont(event:Event):void {
tff.font = script1_lb.selectedItem.data;
MovieClip(parent).design_mc.info_txt.embedFonts = true;
MovieClip(parent).design_mc.info_txt.setTextFormat(tff.font);

}

When trying to apply the font akaDora, this is the error I’m getting:

TypeError: Error #1034: Type Coercion failed: cannot convert "akaDora" to flash.text.TextFormat.

I’ve been looking at this for hours and reading the help files but can’t seem to see what I might be missing. Can someone help? Thanks

Upvotes: 0

Views: 2197

Answers (1)

Chunky Chunk
Chunky Chunk

Reputation: 17217

it appears your trying to set the text format as your TextFormat object's font rather than the actual TextFormat, which the setTextFormat() method accepts as it's parameter:

you have this:

MovieClip(parent).design_mc.info_txt.setTextFormat(tff.font);

change it to this:

MovieClip(parent).design_mc.info_txt.setTextFormat(tff);

Upvotes: 1

Related Questions