BlairHippo
BlairHippo

Reputation: 9658

Using fx/mx:Label with Flex 4

I'm doing a text-heavy demo app in Flex 4. I'd very much like to use the old mx:Label object so that I can access htmlText and save myself some bother formatting the text.

Unfortunately, I can't figure out how to use it. Research elsewhere has told me to just use <fx:Label>, but that produces Could not resolve <fx:Label> to a component implementation. Inserting an mx namespace (xmlns:mx="library://ns.adobe.com/flex/mx") leads to fundamentally the same thing (Could not resolve <mx:Label> to a component implementation.).

Where am I going wrong?

Upvotes: 0

Views: 106

Answers (1)

Sunil D.
Sunil D.

Reputation: 18193

There is no <fx:Label /> component, however the Spark (Flex 4) version of that is <s:Label />.

As you know, the Spark version doesn't have an htmlText property. But there's no reason you can't use the <mx:Label /> in your project. Here's a sample application that does just that:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:local="*">

        <mx:Label htmlText="this is &lt;b&gt;bold&lt;/b&gt;"/>

</s:Application>

Note that in the project's properties, under the "Flex Build Path" section, you need to enable both the Spark and MX component sets. Perhaps your project's settings are only including the Spark component set.

[Edit]

Another option is to use the Spark <s:RichText /> component. This doesn't have an htmlText property either. However, you can set the TextFlow property that this component uses, and import HTML into the TextFlow by doing TextConverter.importToFlow(sourceHtml, TextConverter.TEXT_FIELD_HTML_FORMAT). It's obviously more work than just using the htmlText property of the mx component, but this will give you fancy TLF text (which the mx component doesn't use).

Upvotes: 1

Related Questions