weixin_43187895
Minnix
采纳率0%
2018-12-21 20:09

Flash3.0制作一个拼图小游戏,可是显示TypeError: Error #1009: 无法访问空对象引用的属性或方法,求助

在做Flash期末作业,制作一个拼图小游戏,代码是看着课本改造了一些。后来给游戏添加一个封面和跳转,就出现问题了,拼图不能移动,只是图片,不知道怎么改,向大佬们求助一下。

报错信息:
TypeError: Error #1009: 无法访问空对象引用的属性或方法。
at PuzzleGame/Reset()
at PuzzleGame()

PuzzleGame.as (文档类)文件代码:
package
{
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;

public class PuzzleGame extends MovieClip
{
    public var M1_Array: Array;
    public var M1_nRow, M1_nCol: int;
    public function PuzzleGame() 
    {
        Reset();
        this.stage.addEventListener(KeyboardEvent.KEY_UP,onKeyboardUp);
        Reset_btn.addEventListener(MouseEvent.CLICK,reset);
    }

    public function reset(e:MouseEvent):void
    {
        Reset();
    }

    public function Reset():void
    {
        SuccessText.visible = false;
        M1_Array = null;
        M1_Array = new Array();
        M1_Array.push(P1);M1_Array.push(P2);M1_Array.push(P3);M1_Array.push(P4);
        M1_Array.push(P5);M1_Array.push(P6);M1_Array.push(P7);M1_Array.push(P8);
        M1_Array.push(P9);M1_Array.push(P10);M1_Array.push(P11);M1_Array.push(P12);
        M1_Array.push(P13);M1_Array.push(P14);M1_Array.push(P15);M1_Array.push(P16);
        M1_nRow = 0; M1_nCol = 0;
        var temp:MovieClip;
        var m,n:int;
        for(var i:int = 0; i < 5; i++)
        {
            m = int(Math.random() * 15 + 1);
            n = int(Math.random() * 15 + 1);
            temp = M1_Array[m];
            M1_Array[m] = M1_Array[n];
            M1_Array[n] = temp;
        }
        setPost();
    }

    public function setPost():void
    {
        var row,col:int;
        for(row = 0; row < 4; row++)
        {
            for(col = 0; col < 4; col++)
            {
                M1_Array[row * 4 + col].x = col * 60;
                M1_Array[row * 4 + col].y = row * 60;
            }
        }
    }

    public function onKeyboardUp(e:KeyboardEvent):void
    {
        switch(e.keyCode)
        {
            case Keyboard.UP:
                Exchange(M1_nRow - 1,M1_nCol);
                break;
            case Keyboard.DOWN:
                Exchange(M1_nRow + 1,M1_nCol);
                break;
            case Keyboard.LEFT:
                Exchange(M1_nRow,M1_nCol - 1);
                break;
            case Keyboard.RIGHT:
                Exchange(M1_nRow,M1_nCol + 1);
                break;
            case Keyboard.SPACE:
                Reset();
                break;
        }

        checkFinish();
    }

    public function Exchange(row:int,col:int):void
    {
        if(SuccessText.visible == true)
            return;
        if(row<0 || row>=4 || col<0 || col>=4)
            return;
        var temp:MovieClip;
        var newIndex:int = row * 4 + col;
        var oldIndex:int = M1_nRow * 4 + M1_nCol;
        temp = M1_Array[newIndex];
        M1_Array[newIndex] = M1_Array[oldIndex];
        M1_Array[oldIndex] = temp;
        M1_nRow = row;
        M1_nCol = col;
        setPost();
    }

    public function checkFinish():void
    {
        if(M1_Array[0] == P1 && M1_Array[1] == P2 && M1_Array[2] == P3 && M1_Array[3] == P4 && 
        M1_Array[4] == P5 && M1_Array[5] == P6 && M1_Array[6] == P7 && M1_Array[7] == P8 && 
        M1_Array[8] == P9 && M1_Array[9] == P10 && M1_Array[10] == P11 && M1_Array[11] == P12 && 
        M1_Array[12] == P13 && M1_Array[13] == P14 && M1_Array[14] == P15 && M1_Array[15] == P16)
        {
            SuccessText.visible = true;
        }
    }
}

}

游戏点击Start后的效果:
图片说明
时间轴上的设置:
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答