Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 as3错误:ReferenceError:错误#1069:在flash.display.Shape上找不到属性键代码,并且没有默认值_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 as3错误:ReferenceError:错误#1069:在flash.display.Shape上找不到属性键代码,并且没有默认值

Actionscript 3 as3错误:ReferenceError:错误#1069:在flash.display.Shape上找不到属性键代码,并且没有默认值,actionscript-3,flash,Actionscript 3,Flash,我正在学习一个关于在as3中构建节奏游戏的教程,我对这门语言非常陌生。运行swf时,输出中出现以下错误: ReferenceError: Error #1069: Property keyCode not found on flash.display.Shape and there is no default value. at source_fla::MainTimeline/makeLvl()[source_fla.MainTimeline::frame10:116] 我已经尝试了以前发布

我正在学习一个关于在as3中构建节奏游戏的教程,我对这门语言非常陌生。运行swf时,输出中出现以下错误:

ReferenceError: Error #1069: Property keyCode not found on flash.display.Shape and there is no default value.
at source_fla::MainTimeline/makeLvl()[source_fla.MainTimeline::frame10:116]
我已经尝试了以前发布到同一错误的一些解决方案,但我无法解决该问题

以下是源代码:

stop();
stage.focus = stage;
//VARIABLES
//sTime is the current frame that is being played
//Once it reaches sTempo, then it will be reset
//and a note will be created
var sTime:int = 0;
//sTempo is how many frames it takes before
//a note is created. Because it's 12, and
//the frame rate is 24, it will take a half of a second
//for a note to be made
var sTempo:Number = 12;
//sNote is the current arrow of the level that is created
//0 makes no arrow
//1 makes a left arrow
//2 makes an up arrow
//3 makes a down arrow
//4 makes a right arrow
var sArrow:int = 0;
//arrowSpeed is how fast the arrow moves up the screen
var arrowSpeed:Number = 10;
//gameIsOver is whether the game's over
var gameIsOver:Boolean = false;
//the score variable
var score:int = 0;
//either perfect, great, nice, or good
var scoreString:String = '';

var combo:int = 0;

var mcHealth:Number = 0;


//Booleans checking if the arrows are touching the receptor
var touchLeft:Boolean = false;
var touchUp:Boolean = false;
var touchDown:Boolean = false;
var touchRight:Boolean = false;

function beginCode():void{
    addEventListener(Event.ENTER_FRAME, makeLvl);

    //make the level array longer
    lvlArrayAll[lvlCurrent].push(0,0,0,0,0);
}

function makeLvl(e:Event):void{
    //code here will create the level
    if(sTime < sTempo){
        //if the required time hasn't reached the limit
        //then update the time
        sTime ++;
    } else {
        //if the time has reached the limit
        //then reset the time
        sTime = 0;
        //if an actual arrow can be made
        if(lvlArrayAll[lvlCurrent][sArrow] != 0){
            var currentArrow:MovieClip; //this will hold the current arrow
            if(lvlArrayAll[lvlCurrent][sArrow] == 1){
                //place a left note onto the stage
                currentArrow = new arrowLeft();
                //set the _x value of the note so that it is in the
                //right place to touch the receptor
                currentArrow.x = 105    ;
                //set the note's y coordinate off of the stage
                //so that the user can't see it when it appears
                currentArrow.y = 0;
                //setting the key that needs to be pressed
                currentArrow.keyCode = 68;
                addChild(currentArrow);//add it to stage
            } else if(lvlArrayAll[lvlCurrent][sArrow] == 2){
                //place an up note onto the stage
                currentArrow = new arrowUp();
                currentArrow.x = 230;
                currentArrow.y = 0;
                currentArrow.keyCode = 70;
                addChild(currentArrow);
            } else if(lvlArrayAll[lvlCurrent][sArrow] == 3){
                //place a down note onto the stage
                currentArrow = new arrowDown();
                currentArrow.x = 355;
                currentArrow.y = 0;
                currentArrow.keyCode = 74;
                addChild(currentArrow);
            } else if(lvlArrayAll[lvlCurrent][sArrow] == 4){
                //place a right note onto the stage
                currentArrow = new arrowRight();
                currentArrow.x = 480;
                currentArrow.y = 0;
                currentArrow.keyCode = 75;
                addChild(currentArrow);
            }
        }
        //get the next arrow if it the song isn't finished
        if(sArrow < lvlArrayAll[lvlCurrent].length){
            sArrow ++;
        } else {
            //if the song is finished, then reset the game
            gotoAndStop('win');
            gameIsOver = true;
            //then remove this enter_frame listener
            removeEventListener(Event.ENTER_FRAME, makeLvl);
        }
    }

    //checking if mcReceptor is touching any arrows
    //first we reset the variables we got last time just in case they aren't true anymore
    touchLeft = false;
    touchUp = false;
    touchDown = false;
    touchRight = false;
    //this for loop will be used for the hit testing
    for(var i:int = 0;i<numChildren;i++){
        var target:Object = getChildAt(i);
        if(target.keyCode != null && target.hitTestObject(mcReceptor)){//if the object is an arrow and the receptor is touching it
            if(target.keyCode == 68){//if left arrow
                touchLeft = true;
            } else if(target.keyCode == 70){//if up arrow
                touchUp = true;
            } else if(target.keyCode == 74){//if down arrow
                touchDown = true;
            } else if(target.keyCode == 75){//if right arrow
                touchRight = true;
            }
        }
    }
    //changing the score text
    mcTxt.txtScore.text = 'Score:  '+score;
    mcTxt.txtCombo.text = 'Combo:  '+combo;
    mcTxt.txtScoreString.text = scoreString;
}

//this function will change the health depending on how much health change
//it needs, positive or negative
function changeHealth(healthDiff:Number):void{
    healthDiff = 100;//only changes in percentages
    //checking if the health is already at it's full
    //or will be full after this hit
    if(mcHealth + healthDiff >= 100){
        mcHealth = 100;
    } else if(mcHealth + healthDiff <= 0){
        //checking if the health will be equal or below 0
        gotoAndStop('lose');
        gameIsOver = true;
        removeEventListener(Event.ENTER_FRAME, makeLvl);
    } else {
        //if there are no problems
        mcHealth += healthDiff;
    }
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeys);
function checkKeys(event:KeyboardEvent):void{
    //if the left key is down and no left arrows are touching the receptor
    if(event.keyCode == 68 && !touchLeft){ 
        changeHealth(-10);//make the health go down
        combo = 0;
        scoreString = 'Bad';
    } else if(event.keyCode == 70 && !touchUp){//and so on
        changeHealth(-10);
        combo = 0;
        scoreString = 'Bad';
    } else if(event.keyCode == 74 && !touchDown){
        changeHealth(-10);
        combo = 0;
        scoreString = 'Bad';
    } else if(event.keyCode == 75 && !touchRight){
        changeHealth(-10);
        combo = 0;
        scoreString = 'Bad';
    }
}

beginCode();
stop();
阶段。焦点=阶段;
//变数
//sTime是正在播放的当前帧
//一旦到达sTempo,它将被重置
//将创建一个注释
变量时间:int=0;
//sTempo是之前需要的帧数
//将创建一个注释。因为是12,而且
//帧速率是24,需要半秒
//要做笔记吗
var sTempo:Number=12;
//sNote是所创建级别的当前箭头
//0不成箭
//1表示左箭头
//2组成一个向上箭头
//3表示向下箭头
//4表示向右箭头
var sArrow:int=0;
//箭头速度是箭头在屏幕上向上移动的速度
变量箭头速度:数字=10;
//游戏结束就是游戏是否结束
var gameIsOver:布尔值=假;
//分数变量
变量得分:int=0;
//要么完美,要么很棒,要么很好,要么很好
var scoreString:String='';
变量组合:int=0;
var mcHealth:Number=0;
//布尔值检查箭头是否接触接收器
var touchleet:Boolean=false;
var修补:布尔值=假;
var着陆:布尔值=假;
var touchRight:Boolean=false;
函数beginCode():void{
addEventListener(Event.ENTER_FRAME,makeLvl);
//使水平阵列更长
lvlArrayAll[lvlCurrent].push(0,0,0,0);
}
函数makeLvl(e:事件):void{
//这里的代码将创建级别
如果(时间对于(var i:int=0;i在迭代
numChildren
时,有必要检查对象是否为箭头。
也许您可以通过是否具有
keyCode
属性来区分它

尝试使用
Object.hasOwnProperty(属性名称)
方法

if (target.hasOwnProperty("keyCode")){
    // access target.keyCode here.
}
或者这也可能有效

if (target is arrowLeft || target is arrowUp || target is arrowDown || target is arrowRight){
    // the target should be arrow class
    // access target.keyCode here.
}

//此for循环将用于命中测试

对于(var i:int=0;i在迭代
numChildren
时,有必要检查对象是否为箭头。
也许您可以通过是否具有
keyCode
属性来区分它

尝试使用
Object.hasOwnProperty(属性名称)
方法

if (target.hasOwnProperty("keyCode")){
    // access target.keyCode here.
}
或者这也可能有效

if (target is arrowLeft || target is arrowUp || target is arrowDown || target is arrowRight){
    // the target should be arrow class
    // access target.keyCode here.
}

//此for循环将用于命中测试
对于(变量i:int=0;i