Flash AS3 settings File box focus method

Source: Internet
Author: User
Tags addchild

Flash AS3 settings File box focus method
Lash files and ActionScript files should be placed in the same directory, and note that the ActionScript file name is the class name, in the Flash file's Properties panel class to fill in the 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));
}

}
}

Set the space text to the focus code

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;

}

}
}

Set the text content and set it to the selected state

Package {

  Import Flash.display.Sprite;
  Import Flash.text.TextField;
  public class main extends Sprite {
    public function main ( ) {
  &nbs p;   var Field:textfield = new TextField ( );
   
        stage.focus = field;                  //Set The focus to the text field
& nbsp;       Field.text = "This is example text"; //Set The text value
   ;      field.setselection (0, 0);
       
       
         Trace (Field.caretindex);
        addChild (field);
   }
 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.