LinkElement become NOT clickable when it scroll out of TextArea view
Hi:
I am writing a online call center product with flash builder 4.5.
I found a tricky problem with LinkElement.
I use the TextArea as the display stage for each incoming and outgoing message. Obviously, the messages includes image and href.
I use LinkElement to display them.
As conversation continues, the TextArea's view scrolls to display more and more content.
When LinkElement scrolls out of the viewable area of TextArea, it becomes NOT clickable!!!
If I change the size or height of TextArea, make the LinkElement shows in view of TextArea, it becomes Clickable.
But changing the size of TextArea is not a workable way to fix this problem, espetially for a long conversation.
The source code is too long, I have to show some snapshot.
=============================================================================
Following is function to generate Paragraph to be inserted into TextArea.
| private function imageToLocalParagraph( | ||||||
| role:int, customerId:int, stationId:int, imageTitle:String, imageUrl:String):ArrayList{ | ||||||
| var selfName:String = getRoleName(role, customerId, stationId); | ||||||
| var color:uint = getColor(role); | ||||||
| var timeStr:String = getTimeString(); | ||||||
| var list:ArrayList = new ArrayList(); | ||||||
| var p:ParagraphElement = new ParagraphElement(); | ||||||
| var span:SpanElement = new SpanElement(); | ||||||
| span.text = | ||||||
| timeStr + " " + selfName; | ||||||
| span.fontSize = _fontSize; | ||||||
| span.color = color; | ||||||
| p.addChild(span); | ||||||
| list.addItem(p); | ||||||
| var p2:ParagraphElement = new ParagraphElement(); | ||||||
| var inf:Object = {color:0xFF0000}; | ||||||
| p2.linkHoverFormat = inf; | ||||||
| var link:LinkElement = new LinkElement(); | ||||||
| link.href = imageUrl; | ||||||
| link.target = "_blank"; | ||||||
| link.addEventListener(FlowElementMouseEvent.CLICK, onImageClick); | ||||||
| var linkSpan:SpanElement = new SpanElement(); | ||||||
| linkSpan.text = "点击打开" + imageTitle; | ||||||
| linkSpan.fontSize = _fontSize; | ||||||
| linkSpan.color = color; | ||||||
| link.addChild(linkSpan); | ||||||
| p2.addChild(link); | ||||||
| list.addItem(p2); | ||||||
| return list; | ||||||
| } |
Following is the TextArea that contains each paragraph.
=================================================================
| <s:TextArea id="textArea" | ||||
| editable="false" | ||||
| focusEnabled="true" | ||||
| horizontalCenter="0" | ||||
| width="100%" | ||||
| height="70%"> | ||||
| <s:textFlow> | ||||
| <s:TextFlow> | ||||
| <s:p><s:a href="http://adobe.com/" target="_blank"></s:a></s:p> | ||||
| </s:TextFlow> | ||||
| </s:textFlow> | ||||
| </s:TextArea> |
When sprite is created complete, event listener is set for TextArea and this. ParagraphElementEvent is new defined event to receive paragraph list.
| this.textArea.textFlow.addEventListener( | |||||
| CompositionCompleteEvent.COMPOSITION_COMPLETE, compositionCompleteHandler); | |||||
| this.addEventListener(ParagraphElementEvent.TYPE, onParagraphElementEvent); |
When receiving paragraph list event, TextArea will add it and auto scroll view to bottom.
======================================================================================================
| private function onParagraphElementEvent(event:ParagraphElementEvent):void { |
| if (event.eventId == this._customer.customerId) { | ||||||
| var list:ArrayList = event.paragraphElementList; | ||||||
| for (var i:int = 0; i < list.length; i++) { | ||||||
| var p:ParagraphElement = (ParagraphElement)(list.getItemAt(i)); | ||||||
| this.textArea.textFlow.addChild(p); | ||||||
| } | ||||||
| // auto scrolling to bottom with 3 ways, the last one is perfect | ||||||
| // (1) this.textArea.appendText(""); | ||||||
| // (2) this.textArea.scrollToRange(int.MAX_VALUE, int.MAX_VALUE); | ||||||
| // (3) call scrollToBottom twice when textFlow.addChild and textFlow.CompositionCompleteEvent | ||||||
| scrollToBottom(); | ||||||
| } | ||||||
| } | ||||||
| private function compositionCompleteHandler(event:CompositionCompleteEvent):void { | ||||||
| scrollToBottom(); | ||||||
| } | ||||||
| private function scrollToBottom():void { | ||||||
| this.textArea.validateNow(); | ||||||
| var maximum:Number = this.textArea.scroller.verticalScrollBar.maximum; | ||||||
| this.textArea.scroller.verticalScrollBar.value = maximum; | ||||||
| } | ||||||
I don't think it is a problem of Flash builder 4.5.
LinkElement is a commen component.
Thanks
Steven
