论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS编程教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

仿劲舞团游戏按键的实现(as2.0)

文章类别:Flash AS编程 | 发表日期:2008-10-6 17:35:48


  

 

源文件下载地址:
/upimg/soft/1/1_080122170619.rar

/*
自娱自乐 www.mygamemylove.com
我的经验与你分享
mygamemylove@qq.com
*/
//舞台高,宽
var numFlashW:Number = 450;
var numFlashH:Number = 300;
//按键的长和宽
var numMcKeyWH:Number = 58;
//
var root:MovieClip = _root;
//生成一组按键信息////////////////////////////////////////
//间距
var numKeysJJ:Number = 5;
function showKeys(strThisKeys:String) {
var mcKeys:MovieClip = root.createEmptyMovieClip("mcKeys", root.getNextHighestDepth());
mcKeys._x = (numFlashW-strThisKeys.length*(numMcKeyWH+numKeysJJ))/2;
mcKeys._y = (numFlashH-numMcKeyWH)/2;
//
//0 up 90 right 180 down 270 left
for (var i:Number = 0; i<strThisKeys.length; i++) {
  var numTemRotation = Number(strThisKeys.substr(i, 1))*90;
  with (root.mcKeys.attachMovie("showkey", "mcKey"+String(i), i, {_width:numMcKeyWH, _height:numMcKeyWH, _x:i*(numMcKeyWH+numKeysJJ), _y:0, _rotation:numTemRotation})) {
   mcUp.gotoAndStop(1);
   //mcBak.stop();
  }
}
}
//选重状态mcBak mcUp
function steKeySelect(mc:MovieClip) {
mc.mcBak.gotoAndStop(2);
mc.mcUp.gotoAndStop(1);
}
steKeySelect(root.mcKey2);
//
//提示信息
var txtTalkYou:TextField
function txtTrace(strA):Void{
txtTalkYou.text=strA+"_"+numNowKeys+""+numNowKeyOneI
}
//按键////////////////////////////////////////////////
//
//所以按键的内容
var arrKeysList:Array = ["0123", "1231", "1233","332211","11103","00321"];
var numNowKeys:Number = 0;
var numNowKeyOneI:Number = 0;
//显示第一组按键
showKeys(arrKeysList[numNowKeys]);
//获得当前要按的键
function getDownKey():Number {
return Number(arrKeysList[numNowKeys].substr(numNowKeyOneI, 1));
}
//
function ifKeyOk() {
with (root.mcKeys["mcKey"+numNowKeyOneI]) {
  mcUp.gotoAndStop(2);
  mcBak.gotoAndStop(2);
}
//
numNowKeyOneI++;
}
//事件
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
switch (Key.getCode()) {
case Key.SPACE :
  //trace("SPACE");
  var isTemAllIsDownKeysNow:Boolean = false;
  for (var prop in root.mcKeys) {
   if (root.mcKeys[prop].mcUp._currentframe == 2 && root.mcKeys[prop].mcBak._currentframe == 2) {
    isTemAllIsDownKeysNow = true;
   } else {
    isTemAllIsDownKeysNow = false;
    break;
   }
  }
  //
  if (isTemAllIsDownKeysNow) {
   txtTrace("按对了");
  } else {
   txtTrace("按错了");
  }
  //换下一组
  root.mcKeys.removeMovieClip()
  numNowKeyOneI=0
  numNowKeys++
  if(numNowKeys==arrKeysList.length-1){
   numNowKeys=0
  }
  showKeys(arrKeysList[numNowKeys]);
  //
  break;
case Key.LEFT :
  //trace("left");
  if (getDownKey() == 3) {
   ifKeyOk();
  }
  break;
case Key.UP :
  //trace("UP");
  if (getDownKey() == 0) {
   ifKeyOk();
  }
  break;
case Key.RIGHT :
  //trace("RIGHT");
  if (getDownKey() == 1) {
   ifKeyOk();
  }
  break;
case Key.DOWN :
  //trace("DOWN");
  if (getDownKey() == 2) {
   ifKeyOk();
  }
  break;
}
};
Key.addListener(keyListener);
视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058