1.先下载Vendy.KeyBoard.swc放到libs文件夹下。
2.添加如下代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:VendyKeyBoard="VendyKeyBoard.*"
creationComplete="appInit(event)">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import VendyKeyBoard.KeyBoardEvent;
import mx.events.FlexEvent;
//键盘输入
[Bindable]
private var InputWord:String;
//初始化
protected function appInit(event:FlexEvent):void{
mykeyboard.SetKeyBoard="数字";
InputWord="";
}
protected function mykeyboard_inputHandler(e:KeyBoardEvent):void
{
switch(e.type){
case "input":
InputWord+=e.InputWord;
break;
case "boardChange":
//InputType=mykeyboard.GetInputType
break;
case "del":
InputWord=InputWord.slice(0,InputWord.length-1);
break;
}
}
protected function mykeyboard_delHandler(e:KeyBoardEvent):void
{
switch(e.type){
case "input":
InputWord+=e.InputWord;
break;
case "boardChange":
//InputType=mykeyboard.GetInputType
break;
case "del":
InputWord=InputWord.slice(0,InputWord.length-1);
break;
}
}
protected function mykeyboard_boardChangeHandler(e:KeyBoardEvent):void
{
switch(e.type){
case "input":
InputWord+=e.InputWord;
break;
case "boardChange":
//InputType=mykeyboard.GetInputType
break;
case "del":
InputWord=InputWord.slice(0,InputWord.length-1);
break;
}
}
protected function key_clickHandler(event:MouseEvent):void {
if(this.mykeyboard.visible == false) {
this.mykeyboard.x = this.jianpan.x-25;
this.mykeyboard.y = this.jianpan.y+25;
kbFadeEft.play();
// this.mykeyboard.visible = true;
this.upwd.enabled = false;
} else {
kbFadeEftOut.play();
// this.mykeyboard.visible = false;
this.upwd.enabled = true;
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<s:Fade id="kbFadeEft" target="{mykeyboard}" alphaFrom="0" alphaTo="1"
duration="1000" effectEnd="mykeyboard.visible = true"/>
<s:Fade id="kbFadeEftOut" target="{mykeyboard}" alphaFrom="1" alphaTo="0"
duration="500" effectEnd="mykeyboard.visible = false"/>
</fx:Declarations>
<s:Label text="密码" x="40" y="60"/>
<s:TextInput id="upwd" x="120" y="60" width="106"
displayAsPassword="true" text="{InputWord}"/>
<mx:Image id="jianpan" source="screenshot.png" x="228" y="60"
width="22" height="22" click="key_clickHandler(event)"/>
<VendyKeyBoard:KeyBoard id="mykeyboard" x="115" y="165"
scaleX="0.25" scaleY="0.16" visible="false"
input="mykeyboard_inputHandler(event)"
del="mykeyboard_delHandler(event)"
boardChange="mykeyboard_boardChangeHandler(event)"/>
</s:Application>
3.运行。