0

当我玩 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]

这是我的第一帧代码:

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,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0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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 的评论:

当我在循环中执行我的函数,时,我的不同级别 ( LVL2, LVL3, LVL4) 未正确初始化,范围从.lvl2lvl3lvl4frame 3line 64 to 110

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

4

1 回答 1

1

One: You have hardcoded tableau1 in all your functions below level creation, including collisions.

Two: You erase tableau1 on hittest event.

Three: Your Pac object is undefined if your current frame is not 3, as the layout is written as keyframes, but you don't remove ALL the listeners that target Pac, only the one that's attached to the colliding block.

And four: When you build the array, its length is 5, but you iterate both row and column from 0 to length-1, causing your level to have only 5 columns. Instead, you need to run the inner cycle until tableau1[0].length, like you do in collisions.

You really need to learn to debug your code, and to trace what is called and from where.

于 2013-03-07T10:02:55.673 回答