/*******************************************************/ /*自定义键盘*/ /*******************************************************/ //50个按钮 var totalBtnNum:int = 50; //每一行有12个按钮 var lineBtnNum:int = 12; //按钮的宽和高 var btnWidth:Number = 30; var btnHeight:Number = 30; //按钮的行和列间距 var rw:Number = 5; var lw:Number = 5; //整体按钮的左上角点 var destPoint:Point = new Point(bgMc.x + 10, bgMc.y + 10); //创建滤镜 //投影 var dsf:DropShadowFilter = new DropShadowFilter(2, 90, 0x333333, 1, 2, 1, 1, 1, false, false, false); //模糊 var bf:BlurFilter = new BlurFilter(1, 1, 1); //发光 var gf:GlowFilter = new GlowFilter(0xFF0000, 1, 6, 6, 1, 1, false, false); //所有字母按钮 var btns:Array = new Array(); var letters:Array = ["ɑ","ā","á","à","ǎ","b","c","d","e","ē", "é","ě","è","f","ɡ","h","i","ī","í","ǐ", "ì","j","k","l","m","n","o","ō","ó","ǒ", "ò","p","q","r","s","t","u","ū","ú","ǔ", "ù","ü","ǖ","ǘ","ǚ","ǜ","w","x","y","z"]; for (var i:int = 1; i <= totalBtnNum; i++) { var btn:Sprite = createBtn(btnWidth, btnHeight, letters[i - 1], 24); btn.name = letters[i - 1]; var t:int = i % lineBtnNum; btn.x = destPoint.x + (btn.width + rw) * int((t != 0?t : lineBtnNum) - 1); btn.y = destPoint.y + (btn.height + lw) * int((i - 1) / lineBtnNum); this.addChild(btn); btns.push(btn); } //回车按钮 var enterBtn:Sprite = createBtn((btnWidth + rw) * 5 - rw, btnHeight, "回车(Enter)", 12); enterBtn.name = "enter"; enterBtn.x = destPoint.x + int(totalBtnNum % lineBtnNum + 3) * (btnWidth + rw); enterBtn.y = destPoint.y + int(totalBtnNum / lineBtnNum) * (btnHeight + lw); this.addChild(enterBtn); btns.push(enterBtn); //删除按钮 var delBtn:Sprite = createBtn((btnWidth + rw) * 2 - rw, btnHeight, "删除(Del)", 12); delBtn.name = "del"; delBtn.x = enterBtn.x + enterBtn.width + 4; delBtn.y = enterBtn.y; this.addChild(delBtn); btns.push(delBtn); //创建按钮监听 var tempBtn:Sprite = new Sprite(); for(i = 0; i < btns.length; i++){ btns[i].addEventListener(MouseEvent.MOUSE_DOWN, downHandler); btns[i].addEventListener(MouseEvent.CLICK, clickHandler); } function downHandler(e:MouseEvent):void{ stage.addEventListener(MouseEvent.MOUSE_UP, upHandler); tempBtn = e.currentTarget as Sprite; tempBtn.filters = [bf, gf];// } function upHandler(e:MouseEvent):void{ stage.removeEventListener(MouseEvent.MOUSE_UP, upHandler); tempBtn.filters = [dsf]; } import com.zkl.maths.test.MathsKeyboardEvent; function clickHandler(e:MouseEvent):void{ var key:String = e.currentTarget.name; var eventString:String = MathsKeyboardEvent.NUMKEY; if (key == "del") { eventString = MathsKeyboardEvent.DELETE; }else if (key == "enter") { eventString = MathsKeyboardEvent.ENTER; } this.dispatchEvent(new MathsKeyboardEvent(eventString, key)); } //创建按钮 function createBtn(w:Number, h:Number, txt:String = null, size:Number = 20):Sprite{ var btn:Sprite = new Sprite(); btn.graphics.beginFill(0xFFFFFF); btn.graphics.drawRoundRect(0, 0, w, h, 8, 8); btn.graphics.endFill(); btn.filters = [dsf]; if(txt != null){ var field:TextField = new TextField(); field.defaultTextFormat = format(size); field.autoSize = TextFieldAutoSize.CENTER; field.selectable = false; field.text = txt; //field.width = 20; //field.height = 20; field.x = (w - field.width) / 2; field.y = (h - field.height) / 2; btn.addChild(field); } btn.blendMode = BlendMode.LAYER; return btn; } function format(size:Number):TextFormat{ var format:TextFormat = new TextFormat(); format.font = "宋体"; format.size = size; format.color = 0x666666; return format; } //