·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]一个自定义键盘源代码

时间:2014-01-03 11:09zpointer.iteye.com
[AS3]一个自定义键盘源代码,自定义键盘,as3键盘

[AS3]一个自定义键盘源代码

  1. /*******************************************************/ 
  2. /*Cuplayer.com自定义键盘*/ 
  3. /*******************************************************/ 
  4.  
  5. //Cuplayer.com50个按钮 
  6. var totalBtnNum:int = 50
  7. //每一行有12个按钮 
  8. var lineBtnNum:int = 12
  9. //按钮的宽和高 
  10. var btnWidth:Number = 30
  11. var btnHeight:Number = 30
  12. //按钮的行和列间距 
  13. var rw:Number = 5
  14. var lw:Number = 5
  15. //整体按钮的左上角点 
  16. var destPoint:Point = new Point(bgMc.x + 10, bgMc.y + 10); 
  17.  
  18. //Cuplayer.com创建滤镜 
  19. //Cuplayer.com投影 
  20. var dsf:DropShadowFilter = new DropShadowFilter(2, 90, 0x333333, 1, 2, 1, 1, 1, false, false, false); 
  21. //Cuplayer.com模糊 
  22. var bf:BlurFilter = new BlurFilter(1, 1, 1); 
  23. //Cuplayer.com发光 
  24. var gf:GlowFilter = new GlowFilter(0xFF0000, 1, 6, 6, 1, 1, false, false); 
  25.  
  26.  
  27. //Cuplayer.com所有字母按钮 
  28. var btns:Array = new Array(); 
  29. var letters:Array = ["ɑ","ā","á","à","ǎ","b","c","d","e","ē", 
  30.                      "é","ě","è","f","ɡ","h","i","ī","í","ǐ", 
  31.                      "ì","j","k","l","m","n","o","ō","ó","ǒ", 
  32.                      "ò","p","q","r","s","t","u","ū","ú","ǔ", 
  33.                      "ù","ü","ǖ","ǘ","ǚ","ǜ","w","x","y","z"]; 
  34. for (var i:int = 1; i <= totalBtnNum; i++) { 
  35.     var btn:Sprite = createBtn(btnWidth, btnHeight, letters[i - 1], 24); 
  36.     btn.name = letters[i - 1]; 
  37.     var t:int = i % lineBtnNum; 
  38.     btn.x = destPoint.x + (btn.width + rw) * int((t != 0?t : lineBtnNum) - 1); 
  39.     btn.y = destPoint.y + (btn.height + lw) * int((i - 1) / lineBtnNum); 
  40.     this.addChild(btn); 
  41.     btns.push(btn); 
  42.  
  43. //回车按钮 
  44. var enterBtn:Sprite = createBtn((btnWidth + rw) * 5 - rw, btnHeight, "回车(Enter)", 12); 
  45. enterBtn.name = "enter"
  46. enterBtn.x = destPoint.x + int(totalBtnNum % lineBtnNum + 3) * (btnWidth + rw); 
  47. enterBtn.y = destPoint.y + int(totalBtnNum / lineBtnNum) * (btnHeight + lw); 
  48. this.addChild(enterBtn); 
  49. btns.push(enterBtn); 
  50.  
  51. //删除按钮 
  52. var delBtn:Sprite = createBtn((btnWidth + rw) * 2 - rw, btnHeight, "删除(Del)", 12); 
  53. delBtn.name = "del"
  54. delBtn.x = enterBtn.x + enterBtn.width + 4; 
  55. delBtn.y = enterBtn.y; 
  56. this.addChild(delBtn); 
  57. btns.push(delBtn); 
  58.  
  59. //创建按钮监听 
  60. var tempBtn:Sprite = new Sprite(); 
  61. for(i = 0; i < btns.length; i++){ 
  62.     btns[i].addEventListener(MouseEvent.MOUSE_DOWN, downHandler); 
  63.     btns[i].addEventListener(MouseEvent.CLICK, clickHandler); 
  64. function downHandler(e:MouseEvent):void{ 
  65.     stage.addEventListener(MouseEvent.MOUSE_UP, upHandler); 
  66.     tempBtn = e.currentTarget as Sprite; 
  67.     tempBtn.filters = [bf, gf];// 
  68. function upHandler(e:MouseEvent):void{ 
  69.     stage.removeEventListener(MouseEvent.MOUSE_UP, upHandler); 
  70.     tempBtn.filters = [dsf]; 
  71. import com.zkl.maths.test.MathsKeyboardEvent; 
  72. function clickHandler(e:MouseEvent):void{ 
  73.     var key:String = e.currentTarget.name; 
  74.     var eventString:String = MathsKeyboardEvent.NUMKEY; 
  75.     if (key == "del") { 
  76.         eventString = MathsKeyboardEvent.DELETE; 
  77.     }else if (key == "enter") { 
  78.         eventString = MathsKeyboardEvent.ENTER; 
  79.     } 
  80.     this.dispatchEvent(new MathsKeyboardEvent(eventString, key)); 
  81.  
  82. //创建按钮 
  83. function createBtn(w:Number, h:Number, txt:String = nullsize:Number = 20):Sprite{ 
  84.     var btn:Sprite = new Sprite(); 
  85.     btn.graphics.beginFill(0xFFFFFF); 
  86.     btn.graphics.drawRoundRect(0, 0, w, h, 8, 8); 
  87.     btn.graphics.endFill(); 
  88.     btn.filters = [dsf]; 
  89.     if(txt != null){ 
  90.         var field:TextField = new TextField(); 
  91.         field.defaultTextFormat = format(size); 
  92.         field.autoSize = TextFieldAutoSize.CENTER; 
  93.         field.selectable = false
  94.         field.text = txt
  95.         //field.width = 20
  96.         //field.height = 20
  97.         field.x = (w - field.width) / 2; 
  98.         field.y = (h - field.height) / 2; 
  99.         btn.addChild(field); 
  100.     } 
  101.     btn.blendMode = BlendMode.LAYER; 
  102.     return btn; 
  103.  
  104. function format(size:Number):TextFormat{ 
  105.     var format:TextFormat = new TextFormat(); 
  106.     format.font = "宋体"
  107.     format.size = size; 
  108.     format.color = 0x666666
  109.     return format; 
  110. // 

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器