I’m trying to use a FXG image as the icon for a button that also contains a caption. My FXG file is located at resources/SpeakerIcon.fxg and my attempted usage looks like this in my mxml file:
<mx:Button id="audioButton" label="Audio"
....
icon="{resources.SpeakerIcon}"/>
When I try to use this I get “TypeError: Error #1034: Type Coercion failed: cannot convert resources::SpeakerIcon@41fa0e1 to mx.core.IFlexDisplayObject.” My research indicates that FXG files should be s:Graphics which do implement IFlexDisplayObject http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/primitives/Graphic.html.
What simple thing am I missing?
The
<s:Graphics/>object is different than the<Graphics/>tag in an FXG document.<s:Graphics/>is the base class for Spark primitive shape components (like<s:Rect/>). These are not as lightweight as their FXG counterparts. As such they do not implement theIFlexDisplayObjectinterface (as @Flextras has just posted 🙂FXG assets can be treated as
SpriteVisualElementin your Flex code, which technically means FXG assets implement theIVisualElementinterface.If you can, use the Spark
<s:Button/>class instead of mx. I don’t think<mx:Button/>works with FXG.