开发者

HTML in Flex mobile project

I have flex mobile project, and i need to show HTML text in some view of project. Any solution other than the following will be appreciated. Because following techniques fails if HTML is not well formatted.

1: TextArea.textFlow = TextFlowUtil.importFromString("html 开发者_StackOverflow中文版text goes here");

2: TextArea.textFlow = TextConverter.importToFlow("html text goes here", TextConverter.TEXT_FIELD_HTML_FORMAT);

Thanks, Asif.


<?xml version="1.0" encoding="utf-8"?>
<!-- mobile_text/HTMLTextView.mxml -->
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark" title="HTMLText View"
        creationComplete="initView()">
    <s:layout>
        <s:VerticalLayout/>
</s:layout>
    <fx:Script>
        <![CDATA[
            import spark.components.supportClasses.StyleableTextField;
            private function initView():void {
                StyleableTextField(ta1.textDisplay).htmlText = "TextArea <b>bold</b><i>italic</i>.";
            }
        ]]>
    </fx:Script>
        <s:TextArea id="ta1" width="100%"/>
</s:View>


It is generally considered bad practice to use the TLF Framework in mobile for performance reasons; and I am pretty sure that the TextConverter classes you are referencing are part of TLF.

That said, you do have a few options. Start by reading this documentation on Using HTML Text in Mobile Applications. Here are a relevant passage:

To use the htmlText property in mobile text controls, access the property on the StyleableTextField subcontrol.

I'm pretty sure that Both TextInput and TextArea use the StyleableTextField under the hood in their mobile skins.


You better can use a StageWebView object. StageWebView is a wrapper for the native WebView object. It uses the build-in browser to show HTML. You can also load strings like the folowing example shows:

import flash.media.StageWebView;

var webView = new StageWebView();  
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, this.stage.stageWidth, 100 );
webView.loadString( 'Your HTML Here' );

That's it, cheers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜