我可以玩一次我的水平,我不能做另一个。排列

时间:2013-03-07 09:13:05

标签: arrays actionscript-3

当我正常播放lvl1我的Array版本时,如果我想在其他级别之后执行,则不会构建任何内容。如果我想做其他级别,即使我不执行lvl1,也只构建我的Array的前5列。并且,为了完成,当我完成计时器时,我有这个错误:

TypeError: Error #2007: Parameter hitTestObject must be non-null.
    at flash.display::DisplayObject/_hitTest()
    at flash.display::DisplayObject/hitTestObject()
    at projsolo_fla::MainTimeline/collisions()[projsolo_fla.MainTimeline::frame3:133]

这是我的第1帧代码:

import flash.events.MouseEvent;

//--- Variables: ---

var toucheA: Boolean = false;
var toucheZ: Boolean = false;
var toucheE: Boolean = false;
var toucheR: Boolean = false;
var toucheT: Boolean = false;

var map:Sprite=new Sprite();

//--- Ecouteurs: ---

stage.addEventListener (KeyboardEvent.KEY_DOWN, pressee);
stage.addEventListener (KeyboardEvent.KEY_UP, relachee);
btnLevel.addEventListener (MouseEvent.CLICK, menuLevel);


//--- autre: ---
stop();

stage.displayState=StageDisplayState.FULL_SCREEN; 
stage.scaleMode=StageScaleMode.EXACT_FIT;  
stage.addEventListener (Event.ENTER_FRAME, moove);

//--- Fonction: ---

function pressee (e:KeyboardEvent):void{
    switch (e.keyCode){
        case 65 :
            toucheA=true;
            Pac.y=55;
            break;

        case 90 :
            toucheZ=true;
            Pac.y=105;
            break;

        case 69 :
            toucheE=true;
            Pac.y=155;
            break;

        case 82 :
            toucheR=true;
            Pac.y=205;
            break;

        case 84 :
            toucheT=true;
            Pac.y=255;
            break;

        default :
            break;
    }
}

function relachee (e:KeyboardEvent):void{
    switch (e.keyCode){
        case 65 :
            toucheA=false;
            break;

        case 90 :
            toucheZ=false;
            break;

        case 69 :
            toucheE=false;
            break;

        case 82 :
            toucheR=false;
            break;

        case 84 :
            toucheT=false;
            break;

        default :
            break;
    }
}

function moove (e:Event):void{
    map.x-=5;
}

function menuLevel (e:MouseEvent):void{
    gotoAndStop (2);
}

这是我的第2帧代码:

import flash.events.MouseEvent;

btnMusique1.addEventListener (MouseEvent.CLICK, playLVL1);
btnMusique2.addEventListener (MouseEvent.CLICK, playLVL2);
btnMusique3.addEventListener (MouseEvent.CLICK, playLVL3);
btnMusique4.addEventListener (MouseEvent.CLICK, playLVL4);

function playLVL1 (e:MouseEvent):void{
    gotoAndStop (3);
    lvl1 ();
}

function playLVL2 (e:MouseEvent):void{
    gotoAndStop (3);
    lvl2();
}

function playLVL3 (e:MouseEvent):void{
    gotoAndStop (3);
    lvl3();
}

function playLVL4 (e:MouseEvent):void{
    gotoAndStop(3);
    lvl4();
}

这是我的第3帧代码:

import flash.ui.Keyboard;
import flash.events.Event;
import flash.sampler.NewObjectSample;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.media.SoundChannel;
import flashx.textLayout.formats.BlockProgression;

//--- Variables: ---
stop();

var timer1: Timer=new Timer (70000,1);

var points: Number = 0;

stage.addChild(map);

var tableau1: Array=[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,1,1,0,1,1,1,0,1,1,1,0,0,0,0,1,1],
                     [0,0,0,0,1,1,1,0,0,0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1,0,1,0,1,1],
                     [0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,1,1,1,0,0,0,0,0,1,0,1,0,0,0,0,1,1,0,0,0,0,0,1,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1]];


var L:int=0;
var C:int=0;

// création du tableau.

function lvl1 () {
    for (L=0; L<tableau1.length ;L++){                          
        for(C=0; C<tableau1[1].length ;C++){                    
            if (tableau1[L][C]==1){
                var Block: block=new block();   
                    map.addChild(Block);
                    Block.name="Block_"+L+"_"+C;
                    Block.x=1620+C*60;
                    Block.y=55+L*50;    
                    Block.addEventListener (Event.ENTER_FRAME, collisions);
                    stage.removeEventListener (Event.ENTER_FRAME, lvl1);
            }
        }
    }
}

function lvl2 () {
    for (L=0; L<tableau2.length;L++){
        for(C=0; C<tableau2.length;C++){
            if (tableau2[L][C]==1){
                var Block: block=new block();
                map.addChild(Block);
                Block.name="Block_"+L+"_"+C;
                Block.x=1620+C*60;
                Block.y=55+L*50;
                Block.addEventListener (Event.ENTER_FRAME, collisions);
                stage.removeEventListener (Event.ENTER_FRAME, lvl2);
            }
        }
    }
}

function lvl3 () {
    for (L=0; L<tableau3.length;L++){
        for(C=0; C<tableau3.length;C++){
            if (tableau3[L][C]==1){
                var Block: block=new block();
                map.addChild(Block);
                Block.name="Block_"+L+"_"+C;
                Block.x=1620+C*60;
                Block.y=55+L*50;
                Block.addEventListener (Event.ENTER_FRAME, collisions);
                stage.removeEventListener (Event.ENTER_FRAME, lvl3);
            }
        }
    }
}

function lvl4 () {
    for (L=0; L<tableau4.length;L++){
        for(C=0; C<tableau4.length;C++){
            if (tableau4[L][C]==1){
                var Block: block=new block();
                map.addChild(Block);
                Block.name="Block_"+L+"_"+C;
                Block.x=1620+C*60;
                Block.y=55+L*50;
                Block.addEventListener (Event.ENTER_FRAME, collisions);
                stage.removeEventListener (Event.ENTER_FRAME, lvl4);
            }
        }
    }
}

//--- Ecouteurs: ---

timer1.addEventListener (TimerEvent.TIMER, stoplvl1);
timer1.start();

//--- Fonctions: ---

function stoplvl1 (e:TimerEvent) :void{
    stage.removeEventListener(Event.ENTER_FRAME, moove);
    for (L=0; L<tableau1.length ;L++){                          
        for(C=0; C<tableau1[1].length ;C++){                    
            if (tableau1[L][C]==1){
                tableau1[L][C]=0;
            }
        }
    }
    stage.removeChild(map);
    gotoAndStop(4);
}

function collisions (e:Event):void {
    if(e.target.hitTestObject(Pac)){
        for (L=0; L<tableau1.length ;L++){                          
            for(C=0; C<tableau1[1].length ;C++){                    
                if (tableau1[L][C]==1){
                    tableau1[L][C]=0;
                }
            }
        }   
        e.target.nextFrame();
        e.target.removeEventListener(Event.ENTER_FRAME, collisions);
        points+=1000;
        Scorelvl.text = points.toString();
    }
}

这是我的第4帧代码:

import flash.events.MouseEvent;

ScoreFin.text = points.toString();

btnMenu.addEventListener (MouseEvent.CLICK, retourMenu);

function retourMenu (e:MouseEvent):void{
    gotoAndStop(2);
}

修改 根据OP的评论:

我有不同级别(LVL2LVL3LVL4),当我执行我的函数lvl2lvl3,{时,这些级别未正确初始化循环中的{1}}范围为lvl4 frame 3

不是创建数组,而是只创建前五列,而不创建其余列。

1 个答案:

答案 0 :(得分:1)

一:您已在级别创建的所有功能中对tableau1进行了硬编码,包括collisions

二:你在hittest事件上删除tableau1

三:如果您当前的帧不是3,则您的Pac对象未定义,因为布局被写为关键帧,但您不会删除所有以Pac为目标的侦听器,只删除一个那是附在碰撞块上的。

四:构建数组时,其长度为5,但是您将行和列从0迭代到长度为1,导致您的级别只有5列。相反,您需要在tableau1[0].length之前运行内循环,就像在collisions中一样。

您确实需要学习调试代码,并跟踪调用的内容和来自哪里。