源文件下载地址:
|
/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);