2011-07-19 14 views
0

私はコントロールを派生シンプルなのTextInput、Ctrlキー+ SHFT + Bにその挿入のいくつかのテキストを持っている:TextInputのinsertText()を使用してバインディングを更新するにはどうすればよいですか?

package controls 
{ 
    import flash.events.KeyboardEvent; 
    import flash.ui.Keyboard; 
    import spark.components.TextInput; 

    public class MyTextInput extends TextInput 
    { 
     private const BAM:String = "BAM!"; 

     public function MyTextInput() 
     { 
      super(); 
      this.addEventListener(KeyboardEvent.KEY_DOWN, interceptKey); 
     } 

     protected function interceptKey(event:KeyboardEvent):void 
     { 
      if((event.keyCode == Keyboard.B) && event.ctrlKey && event.shiftKey) 
      { 
       // Insert some text on Ctrl+Shft+B 
       event.preventDefault(); 
       this.insertText(BAM); 
      } 
     } 
    } 
} 

を私はコントロールを使用する簡単なFlexアプリケーションがあります。

<?xml version="1.0" encoding="utf-8"?> 
<s:WindowedApplication 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:controls="controls.*" 
    width="230" height="120" 
    > 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <fx:Script> 
     <![CDATA[ 

      [Bindable] 
      private var text:String; 
     ]]> 
    </fx:Script> 
    <controls:MyTextInput left="10" right="10" top="10" text="@{text}"/> 
    <s:Label left="10" right="10" bottom="10" text="{text}"/> 
</s:WindowedApplication> 

ラベルフィールドをCtrl + Shft + Bを呼び出すと、期待されるテキストがTextInput派生コントロールに表示されますが、Labelでは表示されません。

+0

Flash Builder 4.5.1。 –

答えて

0

「変更」イベントをディスパッチするようにしてください:

protected function interceptKey(event:KeyboardEvent):void 
    { 
     if((event.keyCode == Keyboard.B) && event.ctrlKey && event.shiftKey) 
     { 
      // Insert some text on Ctrl+Shft+B 
      event.preventDefault(); 
      this.insertText(BAM); 
      dispatchEvent(new Event("textChanged")); 
     } 
    } 

従って私は決して結合トリガーない、決してイベントを発生しない、設定されたテキストの方法を、使用しないinsertTextメソッドの実装を想定しています。

+0

または 'dispatchEvent(new Event(Event.CHANGE));'? –

0

insertTextを使用しないでください。私はそれが視覚的な外観のためだと信じていますが、実際には 'テキスト'プロパティを変更することはありません。何かがある場合はinsertText(BAM);text += BAM;に置き換えてください。

関連する問題