【转自TICORE】【HOW TO 系列】讓 Flex 內不可選擇的文字超連結生效

在 Flash 內,不可選擇的 (unselectable) TextField 仍可保留 HTML 超連結功能但是 Flex 卻不行查文件上也有寫到 Label.selectable其實不光是 Label, Text 組件不行任何一個在 Flex App 下的 unselectable TextField 超連結都會失效這樣需要用到不可選擇的超連結文字時就很不方便

Flex 超連結失效測試程式:

   
   
<? xmlversion = " 1.0 " encoding = " utf-8 " ?>
< mx:Applicationxmlns:mx = " http://www.adobe.com/2006/mxml "
fontSize
= " 12 " backgroundColor = " #F0F0F0 " >
< mx:Script >
<! [CDATA[
importflash.events.
* ;
importmx.managers.FocusManager;

public functiononTxtLink(evtObj:Event): void ... {
textArea.text
+=evtObj+" ";
}

]]
>
</ mx:Script >
< mx:Labelselectable = " false " link = " onTxtLink(event) " >
< mx:htmlText >
<! [CDATA[FlexLabel: < ahref = ' event:linkEvent ' > LinkEventText </ a > | ]] >
<! [CDATA[ < ahref = ' http://ticore.blogspot.com ' target = ' _blank ' > Ticore ' sBlog</a>]]>
</ mx:htmlText >
</ mx:Label >

< mx:Textselectable = " false " link = " onTxtLink(event) " >
< mx:htmlText >
<! [CDATA[FlexText: < ahref = ' event:linkEvent ' > LinkEventText </ a > | ]] >
<! [CDATA[ < ahref = ' http://ticore.blogspot.com ' target = ' _blank ' > Ticore ' sBlog</a>]]>
</ mx:htmlText >
</ mx:Text >

< mx:Buttonlabel = " ClearLog " click = " textArea.text=''; " />
< mx:TextAreaid = " textArea " width = " 100% " height = " 100% " />
</ mx:Application >

於是花了不少力氣去追蹤原因
終於發現是 Flex 內的 FocusManager 刻意攔截下 unselectable TextField Focus 事件
這也間接造成超連結失效

既然知道問題是出在 FocusManager 上
問題就比較好處理了
以下是變通方式,讓 FocusManager 短暫失效一下~

   
   
<? xmlversion = " 1.0 " encoding = " utf-8 " ?>
< mx:Applicationxmlns:mx = " http://www.adobe.com/2006/mxml "
fontSize
= " 12 " backgroundColor = " #F0F0F0 " >
< mx:Script >
<! [CDATA[
importflash.events.
* ;
importmx.managers.FocusManager;

public functiononTxtLink(evtObj:Event): void ... {
textArea.text
+=evtObj+" ";
}

]]
>
</ mx:Script >
< mx:Labelselectable = " false " link = " onTxtLink(event) "
rollOver
= " focusManager.deactivate() " rollOut = " focusManager.activate() " >
< mx:htmlText >
<! [CDATA[FlexLabel: < ahref = ' event:linkEvent ' > LinkEventText </ a > | ]] >
<! [CDATA[ < ahref = ' http://ticore.blogspot.com ' target = ' _blank ' > Ticore ' sBlog</a>]]>
</ mx:htmlText >
</ mx:Label >

< mx:Textselectable = " false " link = " onTxtLink(event) "
rollOver
= " focusManager.deactivate() " rollOut = " focusManager.activate() " >
< mx:htmlText >
<! [CDATA[FlexText: < ahref = ' event:linkEvent ' > LinkEventText </ a > | ]] >
<! [CDATA[ < ahref = ' http://ticore.blogspot.com ' target = ' _blank ' > Ticore ' sBlog</a>]]>
</ mx:htmlText >
</ mx:Text >

< mx:Buttonlabel = " ClearLog " click = " textArea.text=''; " />
< mx:TextAreaid = " textArea " width = " 100% " height = " 100% " />
</ mx:Application >

Online Demo:

你可能感兴趣的:(Flex,Flash,Adobe)