一聚教程网:一个值得你收藏的教程网站

热门教程

flash as3 设置文件框焦点focus方法

时间:2022-06-28 22:17:20 编辑:袖梨 来源:一聚教程网

flash as3 设置文件框焦点focus方法
lash文件和ActionScript文件要放到同一目录下,并且注意ActionScript文件名为类名,在flash文件的属性面板的类中填写focus。

package {

  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.text.TextFieldType;
  import flash.events.MouseEvent;

  public class Main extends Sprite {

    public function Main(  ) {
      var field:TextField = new TextField(  );
      field.border = true;
      field.background = true;
      field.type = TextFieldType.INPUT;
      addChild(field);
      var button:Sprite = new Sprite(  );
      button.graphics.lineStyle(  );
      button.graphics.beginFill(0xFFFFFF);
      button.graphics.drawRect(0, 0, 100, 50);
      button.graphics.endFill(  );
      button.addEventListener(MouseEvent.CLICK, onClick);
      button.y = 100;
      addChild(button);
    }
   
    private function onClick(event:MouseEvent):void {
      stage.focus = TextField(getChildAt(0));
    }
   
  }
}

将空格text设置为焦点代码

 

package {

  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.text.TextFieldType;
  import flash.events.MouseEvent;

  public class Main extends Sprite {

    public function Main(  ) {
      var field:TextField = new TextField(  );
      field.border = true;
      field.background = true;
      field.type = TextFieldType.INPUT;
      addChild(field);
      var button:Sprite = new Sprite(  );
      button.graphics.lineStyle(  );
      button.graphics.beginFill(0xFFFFFF);
      button.graphics.drawRect(0, 0, 100, 50);
      button.graphics.endFill(  );
      button.addEventListener(MouseEvent.CLICK, onClick);
      button.y = 100;
      addChild(button);
    }
   
    private function onClick(event:MouseEvent):void {
      stage.focus = null;

    }
   
  }
}

设置文本内容并设置其为选择中状态

package {

  import flash.display.Sprite;
  import flash.text.TextField;
  public class Main extends Sprite {
    public function Main(  ) {
      var field:TextField = new TextField(  );
   
        stage.focus = field;                  // Set the focus to the text field
        field.text = "this is example text";  // Set the text value
        field.setSelection(0, 0);
       
       
        trace(field.caretIndex);
        addChild(field);
    }
  }
}

热门栏目