开发者

Problem in Flash TextField

I want to design a calculator by Flash cs5 , I use appendText Method to write the data in the textfield by the Keyboard . My problem is when I start the application I have to Click on the TextField first then type the开发者_如何转开发 numbers . How i can solve it .

Cheers,

Maged


What type of TextField are you using?! Provided that you have created a dynamic TextField with the instance name of textfield, the following should work.

 textfield.restrict = "0-9";
 textfield.text = "";

 function onKeyBoardEvent( event:KeyboardEvent ):void
 {
      var str:String = String.fromCharCode(event.charCode );
      textfield.appendText( str);
  }


you can set focus to the text field as soon as it's added to stage.

frame script:

stage.focus = textFieldInstance;

package:

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;
  }
 }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜