天天看點

Adding links to a Panel container’s status text in Flex

The following example shows how you can assign an HTML formatted string to a Panel container’s status text field using the <code>getStatusTextField()</code> method in the <code>mx_internal</code> namespace.

Full code after the jump.

Since this example uses the mx_internal namespace, you can’t always depend on this behavior to work in future versions of the Flex SDK. Use at your own risk.

&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;!-- http://blog.flexexamples.com/2008/04/17/adding-links-to-a-panel-containers-status-text-in-flex/ --&gt;

&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

        layout="vertical"

        verticalAlign="middle"

        backgroundColor="white"

        creationComplete="init();"&gt;

    &lt;mx:Script&gt;

        &lt;![CDATA[

            import mx.core.IUITextField;

            import mx.controls.Alert;

            private function init():void {

                var tf:IUITextField = panel.mx_internal::getStatusTextField();

                tf.selectable = true;

                tf.addEventListener(TextEvent.LINK, textField_link);

                tf.htmlText = "status with &lt;a href='event:showAlert'&gt;&lt;u&gt;link&lt;/u&gt;&lt;/a&gt;";

            }

            private function textField_link(evt:TextEvent):void {

                Alert.show("Success! A Panel container with a link in the status text.", evt.text);

        ]]&gt;

    &lt;/mx:Script&gt;

    &lt;mx:Panel id="panel"

            title="Title"

            status="status with link"

            width="320"

            height="240"&gt;

        &lt;mx:Text text="Click the link in the Panel container's status bar to launch an Alert control."

                width="100%" selectable="false" /&gt;

        &lt;mx:ControlBar&gt;

            &lt;mx:Text htmlText="&amp;lt;b&amp;gt;Note:&amp;lt;/b&amp;gt; The status text field must have it's selectable property set to true in order to dispatch the link event."

                    width="100%" selectable="false" /&gt;

        &lt;/mx:ControlBar&gt;

    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;

    本文轉自 OldHawk  部落格園部落格,原文連結:http://www.cnblogs.com/taobataoma/archive/2008/04/23/1167844.html,如需轉載請自行聯系原作者

繼續閱讀