The following example shows how you can use a CFF/DefineFont4 embedded font with a Halo/MX List control in Flex 4 by setting the textFieldClass style to the new mx.core.UIFTETextField class.
Full code after the jump.
The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 beta, check out the Adobe Flash Builder 4 page on the Adobe Labs site. To download the latest build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4. For instructions on using the beta Flex 4 SDK in Flex Builder 3, see "Using the beta Flex 4 SDK in Flex Builder 3".
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/11/17/using-a-cff-embedded-font-with-a-halo-list-control-in-flex-4/ --> <s:Application name="Halo_List_textFieldClass_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"> <s:controlBarContent> <s:Label id="sdkVer" fontFamily="df4ster" fontSize="24" initialize="sdkVer.text = mx_internal::VERSION;" /> </s:controlBarContent> <fx:Style> @namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/halo"; @font-face { src: url("C:/Windows/Fonts/Arial.ttf"); embedAsCFF: true; fontFamily: df4ster; } mx|List { color: red; fontFamily: df4ster; fontSize: 16; textFieldClass: ClassReference("mx.core.UIFTETextField"); } </fx:Style> <mx:List id="lst" width="200" horizontalCenter="0" verticalCenter="0"> <mx:dataProvider> <mx:ArrayList> <fx:Object label="Button" icon="@Embed('assets/Button.png')" /> <fx:Object label="ButtonBar" icon="@Embed('assets/ButtonBar.png')" /> <fx:Object label="CheckBox" icon="@Embed('assets/CheckBox.png')" /> <fx:Object label="DataGroup" icon="@Embed('assets/DataGroup.png')" /> <fx:Object label="HGroup" icon="@Embed('assets/HGroup.png')" /> <fx:Object label="HScrollBar" icon="@Embed('assets/HScrollBar.png')" /> <fx:Object label="HSlider" icon="@Embed('assets/HSlider.png')" /> <fx:Object label="Label" icon="@Embed('assets/Label.png')" /> <fx:Object label="List" icon="@Embed('assets/List.png')" /> </mx:ArrayList> </mx:dataProvider> </mx:List> </s:Application>
Or you can set the textFieldClass style on the mx|ListItemRenderer selector, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/11/17/using-a-cff-embedded-font-with-a-halo-list-control-in-flex-4/ --> <s:Application name="Halo_List_textFieldClass_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"> <s:controlBarContent> <s:Label id="sdkVer" fontFamily="df4ster" fontSize="24" initialize="sdkVer.text = mx_internal::VERSION;" /> </s:controlBarContent> <fx:Style> @namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/halo"; @font-face { src: url("C:/Windows/Fonts/Arial.ttf"); embedAsCFF: true; fontFamily: df4ster; } mx|ListItemRenderer { color: red; fontFamily: df4ster; fontSize: 16; textFieldClass: ClassReference("mx.core.UIFTETextField"); } </fx:Style> <mx:List id="lst" width="200" horizontalCenter="0" verticalCenter="0"> <mx:dataProvider> <mx:ArrayList> <fx:Object label="Button" icon="@Embed('assets/Button.png')" /> <fx:Object label="ButtonBar" icon="@Embed('assets/ButtonBar.png')" /> <fx:Object label="CheckBox" icon="@Embed('assets/CheckBox.png')" /> <fx:Object label="DataGroup" icon="@Embed('assets/DataGroup.png')" /> <fx:Object label="HGroup" icon="@Embed('assets/HGroup.png')" /> <fx:Object label="HScrollBar" icon="@Embed('assets/HScrollBar.png')" /> <fx:Object label="HSlider" icon="@Embed('assets/HSlider.png')" /> <fx:Object label="Label" icon="@Embed('assets/Label.png')" /> <fx:Object label="List" icon="@Embed('assets/List.png')" /> </mx:ArrayList> </mx:dataProvider> </mx:List> </s:Application>
This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.
