【问题标题】:Problem in Flash TextFieldFlash 文本字段中的问题
【发布时间】:2011-04-30 21:28:00
【问题描述】:

我想用flash cs5设计一个计算器,我用appendText方法通过键盘将数据写入textfield。 我的问题是,当我启动应用程序时,我必须先单击 TextField,然后输入数字。我该如何解决。

干杯,

魔法

【问题讨论】:

    标签: apache-flex flash actionscript-3 flash-cs4


    【解决方案1】:

    您使用的是什么类型的 TextField?! 假设您已经使用 textfield 的实例名称创建了一个动态 TextField,那么以下应该可以工作。

     textfield.restrict = "0-9";
     textfield.text = "";
    
     function onKeyBoardEvent( event:KeyboardEvent ):void
     {
          var str:String = String.fromCharCode(event.charCode );
          textfield.appendText( str);
      }
    

    【讨论】:

      【解决方案2】:

      您可以在文本字段添加到舞台后立即将其设置为焦点。

      框架脚本:

      stage.focus = textFieldInstance;
      

      包装:

      package
      {
      import flash.display.Sprite;
      import flash.events.Event;
      
      public class DocumentClass extends Sprite
       {
       public function DocumentClass()
        {
        addEventListener(Event.ADDED_TO_STAGE, init);
        }
      
       private function init(evt:Event):void
        {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        stage.focus = textFieldInstance;
        }
       }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多