2011-01-25 56 views

回答

1

这是非平凡的。首先,选择可能需要多个矩形。接下来,没有方便的方法来做到这一点。

这是我必须做的:

 var start:int = op.activePosition < op.anchorPosition ? op.activePosition : op.anchorPosition; 
     var end:int = op.activePosition > op.anchorPosition ? op.activePosition : op.anchorPosition; 

     var textFlow:TextFlow = this.textFlow; 
     var rectangles:Dictionary = new Dictionary(); 

     // For each selected character, make a box 
     for(var i:int=start; i < end; i++) { 

      var flowLine:TextFlowLine = textFlow.flowComposer.findLineAtPosition(i, true); 

      if(rectangles[ flowLine.absoluteStart ] == null) { 
       rectangles[ flowLine.absoluteStart ] = new Rectangle(); 
       (rectangles[ flowLine.absoluteStart ] as Rectangle).x = 0xffffff; 
       (rectangles[ flowLine.absoluteStart ] as Rectangle).right = 0; 
      } 
      var currentRect:Rectangle = rectangles[ flowLine.absoluteStart ]; 

      var textLine:TextLine = flowLine.getTextLine(true); 
      var atomIndex:int = textLine.getAtomIndexAtCharIndex(i); 
      if(atomIndex >= 0) { 
       var atomBounds:Rectangle = textLine.getAtomBounds(atomIndex); 

       var pt:Point = this.globalToLocal(textLine.localToGlobal(new Point(atomBounds.left, atomBounds.top)));      
       if(pt.x <= currentRect.left) { 
        currentRect.left = pt.x; 
        currentRect.top = pt.y; 
       } 

       pt = this.globalToLocal(textLine.localToGlobal(new Point(atomBounds.right, atomBounds.bottom))); 
       if(pt.x >= currentRect.right) { 
        currentRect.right = pt.x; 
        currentRect.bottom = pt.y; 
       }     
      } 
     } 
     return rectangles; 
0

我不相信有一个简单的方法来克服这个总量控制,从在文档环视了一下我看到这一点: http://opensource.adobe.com/wiki/display/flexsdk/Spark+Text+Primitives#SparkTextPrimitives-FTE

[风格(NAME =“focusedTextSelectionColor”,键入=” UINT”格式= “彩色”,继承= “是”)]

[风格(名称= “inactiveTextSelectionColor”,类型= “UINT”,格式= “彩色”,继承= “是”)]

[Style(name =“unfocusedTextSelectionColor”,type =“uint”,format =“Color”,inherit =“yes”)]]

也要注意:

锚点位置 - 一个字符索引,指定在用箭头键扩展选择时保持固定的选择结束。

活动位置 - 一个字符索引,用于指定用箭头键扩展选区时移动的选区的结尾。

由于这些都是唯一的颜色(或指数),我不知道他们是否会得到你想做的所有事物。我曾经在Flex 3中处理过一些自定义文本选择控件,并最终使用了一种“屏幕外缓冲区”,它将屏幕上的TextField与屏幕上的属性相同,然后将字符1逐个转换为1直到我达到所需的宽度,然后我可以找出控件掉落的字符(类似于android选择)。

我建议您在SDK中搜索上述样式(特别是在RichEditableText及其超类中,我会这样做,但现在有相当多的版本,不知道您使用的是哪一种,TLF和FTE都有点不稳定)。一旦找到这些样式的使用位置,您可能会在选择指示符绘图代码附近,并且可能需要从任何类中扩展以覆盖适当的方法。

对不起,我不能给你一个直接的答案,但希望这可以帮助或其他人能够如果有更简单的方法钟声。

Shaun

相关问题