I received an e-Mail from a gentleman named David (thanks David!) who pointed out that my previous blog entry (click here) on this subject did not work for him. After taking a look at David's code I realized some clarification was in order. My original blog entry defined a problem in FlashMX where you could not use a StyleFormat on a component that was masked. I detailed a solution to this problem and at the end of the entry noted that I tested the solution under FlashMX and FlashMX 2004 Professional. What I didn't mention (and I should have) is that I tested the code under FlashMX 2004 Professional with my publish settings set to ActionScript 1.0. David's problem was occuring because he was publishing his code as AS 2.0.

The mechanisms for applying styles to components in FMX and FMX 2004 Professional are different. With AS 2.0 there is no FStyleFormat class but there are some new classes you can make use of to customize the look of your components. Before I show the AS 2.0 code, let me mention that the masking problem (okay, maybe it's not a problem but how they designed components) persists from FMX to FMX 2004. In essence, without embedding fonts you cannot style a component. While my previous blog entry offered the FMX (AS 1.0) solution, here's the FMX 2004 Pro (AS 2.0) solution.

// Create a new Style object.

var aStyleObj = new mx.styles.CSSStyleDeclaration();

// Use the built-in styleName property to name this style.

aStyleObj.styleName = "allComponentStyle";

// Create some style properties for our new style.

aStyleObj.fontSize = 15;

aStyleObj.fontFamily = "Arial";

// You could also set the fontFamily to a Font your created and linked in your library.

// aStyleObj.fontFamily = "myLibraryFont";

aStyleObj.color = 0x000055;

aStyleObj.embedFonts = true;

// Place our new style on the global style list.

_global.styles.allComponentStyle = aStyleObj;

// Apply our new style to the the components on the stage. In this case, a listbox

// component with the instance name myList.

myList.setStyle("styleName", "allComponentStyle");

I'm not going to go into the code above, but know that there are several new classes regarding Text styles and component styling that you can make use of in FMX 2004 Pro.

Thanks again to David for bringing this to my attention.

Aaron West's Gravatar
About this post:

This entry was posted by Aaron West on March 9, 2004 at 4:51 PM. It was filed in the following categories: Flash. It has been viewed 3751 times and has 2 comments.

2 Responses to FlashMX Masking Components Text Problem (FMX 2004 Solution)

  1. rickard

    Hi, when Im using this code to add styles to cpomponents i my flashmovie it gets really slowcfor a while.

    Im using a function that I call about 15 times(alot of comboboxes) to give them styles as they are masked.

    Im calling a function to give them styles

    function comboStyle(path) {
    path.setStyle("styleName", "allComponentStyle");

  2. Setting styles in Flash in an expensive operation. I've set up my code before so I could watch everything that was happening when calling the setStyle() function and in some cases 1,000 different operations kicked off. Because of this expense I would not recommend setting styles in a loop or setting them at small intervals. In the case of your combo boxes, perhaps it makes more sense to apply the styles to your components once, and then mask them. Or, apply the masks and then the styles. You may have to do it in one of these orders to get it to work properly so just play around with it to see.