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.
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.
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 3178 times and has 2 comments.