2012-08-23 60 views
1

我需要在我的Flex 4應用程序中捕獲和修改粘貼操作的內容。我正在偵聽TextOperation.CHANGING事件,拔出PasteOperation並設置其textScrap屬性。似乎一切正常,除了我修改textScrap後,一個換行符被添加到粘貼。我已經創建了一些示例代碼來說明問題的最簡單版本。我實際上並沒有改變副本,我抓住了現有的textScrap的textFlow,使用它創建了一個新的TextScrap,並將其設置在PasteOperation上。我這樣做是爲了排除TextFlow的創作爲這個問題:修改Flex 4中PasteOperation的內容

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 
<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 

<fx:Script> 
    <![CDATA[ 
     import flash.desktop.Clipboard; 
     import flash.desktop.ClipboardFormats; 

     import flashx.textLayout.edit.TextScrap; 
     import flashx.textLayout.elements.TextFlow; 
     import flashx.textLayout.operations.PasteOperation; 
     import flashx.textLayout.tlf_internal; 

     import spark.events.TextOperationEvent; 

     use namespace tlf_internal; 

     protected function textArea_changingHandler(event:TextOperationEvent):void 
     { 
      if (event.operation is PasteOperation) 
      { 
       var pasteOp:PasteOperation = event.operation as PasteOperation; 

       pasteOp.textScrap = new TextScrap(pasteOp.textScrap.textFlow); 
      } 
     } 

    ]]> 
</fx:Script> 
<s:TextArea id="textArea" changing="textArea_changingHandler(event)"/> 
</s:Application> 

由於提前,

格里

+1

我編譯了你的應用程序w/Flex 4.6 SDK,但沒有看到問題,當我粘貼到文本區域時沒有插入換行符。 –

+0

已驗證!這種行爲只發生在SDK 4.1中。謝謝,我甚至沒有想過要嘗試! –

回答

0

這似乎是固定的Adobe在SDK 4.6中的錯誤。

作爲一些附加的信息,替換上面與pasteOp.textScrap行:

pasteOp.textScrap = pasteOp.textScrap.clone()用於拋出一個零指示字例外,並且在4.6太現在工作。

另外,只有當textarea/textinput爲空時纔會出現此錯誤。如果那裏已經有東西,一切都按預期工作。