在Flex应用程序中显示HTML

时间:2020-03-05 18:49:45  来源:igfitidea点击:

我有一些通过Flex应用程序外部的RTF编辑器生成的HTML,但希望在Flex内部显示它。

HTML是简单的HTML标签,诸如样式,锚点以及可能的图像标签之类的东西,是否有一个控件可以让我在Flex中呈现此HTML,还是我必须袖手旁观并自己滚动?

任何想法表示赞赏...谢谢。

解决方案

回答

如果HTML真的很简单,则可以将其显示在常规标签或者textarea组件中。如果它更复杂,则将引用我在此问题中回答的内容。那里的讨论还有更多信息。

If it is complex HTML and Javascript, one possible way is HTMLComponent, a method that uses an iframe over your flash to make it appear like the HTML is in your app. There are a few downsides to this method however - most of them described in detail at Deitte.com.
  
  If this can move offline, you could use Air (it has an mx:HTML component built in). Deitte.com has a detail of this technique as well.

回答

请查看" mx.controls.Label"和" flash.text.TextField"上的文档(这是在Flex中的"文本"或者"标签"控件中显示文本的地方)。 TextField文档指出

The <img> tag lets you embed external image files (JPEG, GIF, PNG), SWF files, and movie clips inside text fields. Text automatically flows around images you embed in text fields. To use this tag, you must set the text field to be multiline and to wrap text.

这意味着我们可以通过将Flex的htmlText属性设置为某些包含<img>标签的HTML来在Flex的Text组件中显示图像。我们不能使用Label,因为它不是多行的。

我注意到,如果文本字段中显示的图像与周围的文本左右对齐(例如," align =" left"`),则文本字段在正确测量其高度时会遇到麻烦。如果我们打算使用对齐的图像,则可能必须在下面添加一些额外的间距以应对。

回答

@mmattax

实际上,我们可以在TextArea组件中显示图像。不过,这种方法并非完全没有问题...