개발관련(Development)/플랙스(Flex), 에어(AIR)
모바일 기기에 키패드 띄우기
Clack
2013. 8. 28. 20:47
textField, textArea 같이 사용자 입력에 반응하는 인터렉티브 객체는 가상 키패드를 띄을 수 있다.
private var bg: Sprite; private var tf: TextField; private var keyboardOverRect: Rectangle; private var overRect: Shape public function SoftKeyboardTest() { super(); bg = new Sprite(); bg.graphics.beginFill( 0x555555 ); bg.graphics.lineStyle( 1, 0xff0000 ); bg.graphics.drawRect( 0, 0, 400, 500 ); this.addChild( bg ); var btn: Sprite = new Sprite(); btn.graphics.beginFill( 0x333333 ); btn.graphics.lineStyle( 1, 0xFF0000 ); btn.graphics.drawRect( 0, 0, 100, 50 ); this.addChild( btn ); btn.x = 50; btn.y = 50; btn.addEventListener(MouseEvent.CLICK, onBtnClick ); tf = new TextField(); tf.border = true; tf.borderColor = 0xFF0000; tf.width = 300; tf.height = 50; tf.background = true; tf.backgroundColor = 0xFFFF00; tf.type = TextFieldType.INPUT; tf.x = 50; tf.y = 400; this.addChild( tf ); tf.addEventListener( SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATE, onKeyboardActivate ); tf.addEventListener( SoftKeyboardEvent.SOFT_KEYBOARD_DEACTIVATE, onKeyboardDeactivate ); this.addEventListener(Event.ADDED_TO_STAGE, onAddStage ); trace("키보드 테스트 생성 완료"); } private function onBtnClick( e:MouseEvent ): void { trace("버튼 클릭"); tf.needsSoftKeyboard = true; this.stage.focus = tf; tf.requestSoftKeyboard(); } private function onAddStage( e:Event ): void { trace("스테이지에 추가됨"); } private function onKeyboardActivate( e:SoftKeyboardEvent ): void { trace( "키보드 나타남", this.stage.softKeyboardRect ); keyboardOverRect = this.stage.softKeyboardRect; overRect = new Shape(); overRect.graphics.beginFill( 0x000000, 0 ); overRect.graphics.drawRect( 0, 0, keyboardOverRect.width, keyboardOverRect.height ); this.stage.addChild( overRect ); overRect.x = keyboardOverRect.x; overRect.y = keyboardOverRect.y; if( tf.hitTestObject( overRect ) ) { trace("텍스트 필드 키보드에 가려짐"); } else { trace("텍스트 필드 키보드에 안가려짐"); } if( e.triggerType == SoftKeyboardTrigger.USER_TRIGGERED ) { trace("사용자가 키보드를 띄웠음"); } else if( e.triggerType == SoftKeyboardTrigger.CONTENT_TRIGGERED ) { trace("컨텐츠에서 키보드를 띄웠음"); } } private function onKeyboardDeactivate( e:SoftKeyboardEvent ): void { trace("키보드 감춰짐"); if( overRect != null && this.stage.contains( overRect ) == true ) { this.stage.removeChild( overRect ); } }
tf.requestSoftKeyboard(); 요렇게 사용자가 텍스트필드를 선택하지 않았을 때에도 키패드를 띄우는 메소드가 있다.