[AS3]一个自定义键盘源代码
[AS3]一个自定义键盘源代码,自定义键盘,as3键盘
[AS3]一个自定义键盘源代码
- /*******************************************************/
- /*Cuplayer.com自定义键盘*/
- /*******************************************************/
- //Cuplayer.com50个按钮
- 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);
- //Cuplayer.com创建滤镜
- //Cuplayer.com投影
- var dsf:DropShadowFilter = new DropShadowFilter(2, 90, 0x333333, 1, 2, 1, 1, 1, false, false, false);
- //Cuplayer.com模糊
- var bf:BlurFilter = new BlurFilter(1, 1, 1);
- //Cuplayer.com发光
- var gf:GlowFilter = new GlowFilter(0xFF0000, 1, 6, 6, 1, 1, false, false);
- //Cuplayer.com所有字母按钮
- 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;
- }
- //
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...