AS3 - 次要平台类绑定错误

时间:2013-06-30 17:50:07

标签: actionscript-3 flash class error-handling flash-cs5

我的代码存在一个小问题。我想链接所有三个类来制作一个简单的平台游戏。这是代码:

数组类:

package 
{
import flash.display.*;
public dynamic class setupStage extends Thiny
{
    var mapWid = 24;
    var mapHei = 40;
    var tileSide = 10;
    var totalTiles = mapWid * mapHei;
    var cell:tile=new tile();

    var firstStage:Array=[
      /*1*/[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
      /*2*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1]
      /*3*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1]
      /*4*/[1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1]
      /*5*/[1,0,0,0,1,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,1]
      /*6*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
      /*7*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
      /*8*/[1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1]
      /*9*/[1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1]
     /*10*/[1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1]
     /*11*/[1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1]
     /*12*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*13*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*14*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1]
     /*15*/[1,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,1]
     /*34*/[1,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1]
     /*35*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*36*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*37*/[1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*38*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*39*/[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]
     /*40*/[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
      ];
    function setupStage()
    {
        trace("access granted");
    }
    function drawMap():void
    {
        for (var i:int=0; i<mapWid; i++)
        {
            for (var u:int=0; u<mapHei; u++)
            {
                cell.gotoAndStop(firstStage[i][u]+1);
                cell.x = tileSide * i;
                cell.y = tileSide * u;
                with (stage)
                {
                    stage.addChild(cell);
                }
            }
        }
    }
}
}

运动类:

package 
{
import flash.display.*;
import flash.utils.*;
import flash.events.*;
import flash.sampler.StackFrame;

public dynamic class JAJEBIE extends Thiny{
var granica:setupStage = new setupStage();
var thinX = 0;
var thinY = 0;
var acc = 6;
var thin:thiny1 = new thiny1();
var przycisk:Object = {};

stage.addEventListener(KeyboardEvent.KEY_DOWN,Move);
stage.addEventListener(KeyboardEvent.KEY_UP,Halt);
//with (thin){addEventListener(Event.ENTER_FRAME,Opadanie);}

function wrzut():void
{
    addChild(thin);
    thin.x = 200;
    thin.y = 390;

}
function Move(k:KeyboardEvent):void
{
    przycisk[k.keyCode] = true;
    if (przycisk[Keyboard.LEFT] && granica.firstStage[thinX][thinY] == 0 && granica.firstStage[thinX - 1][thinY] == 0)
    {
        thin.x = thin.x - 10;
    }
    if (przycisk[Keyboard.RIGHT] && granica.firstStage[thinX][thinY] == 0 &&     granica.firstStage[thinX - 1][thinY] == 0)
    {
        thin.x = thin.x + 10;
    }
    if (przycisk[Keyboard.SPACE])
    {
        acc = 3;
        thin.y = thin.y + 30;
    }
}
//function Opadanie(Event);
//{
//thin.y = thin.y - 30;
//}
function Halt(k:KeyboardEvent):void
{
    przycisk[k.keyCode] = false;
}

}

}

主要文件:

stop();
import flash.events.Event;
import flash.display.DisplayObject;
import flash.utils.*;
import flash.events.*;
import flash.sampler.StackFrame;

stage.addEventListener(Event.ENTER_FRAME,initialize);

function initialize(main_event:Event):void{
        with(setupStage){drawMap();};
        with(JAJEBIE){wrzut();};
        stage.removeEventListener(Event.ENTER_FRAME,initialize);
}

我们尝试了很多东西,但编译器一直在抛出错误,即使我们设法删除所有代码问题,主类似乎也不希望修补所有内容。 任何帮助,将不胜感激! 谢谢!

1 个答案:

答案 0 :(得分:0)

您需要拥有每个类JAJEBIEsetupStage实例,这样您才能获得平台游戏级别和玩家的样本。你的代码说JAJEBIE是一个静态类,因为它没有构造函数,所以你是正确的通过类名来解决它 - 除非错误5000被JAJEBIE抛出,在这种情况下你的代码是错误的。

var jajebie:JAJEBIE;
function initialize(main_event:Event):void{
    jajebie=new JAJEBIE();
    addChild(jajebie);
    addChild(jajebie.granica);
    // while neither is added to stage, they 
    // cannot reach the stage! You have to point them to actual stage.
    jajebie.granica.drawMap(); // now, as we have stage access, draw the map
    jajebie.wrzut();
    stage.removeEventListener(Event.ENTER_FRAME,initialize);
}

此外,您在cell之间只有一个setupStage实例,并且您反复尝试设置其坐标并进入舞台。这种方法是错误的,因为您最终会在屏幕上显示cell的单个实例,它将在右下角。通过在内循环中重新实例化cell来解决此问题。

function drawMap():void     {         for(var i:int = 0; i

最后,您需要学习自己阅读和解释错误消息,以便了解Flash要求您讲述的内容。比如说,错误5000意味着你必须为你的任何一个类扩展一个给定的类(很可能是MovieClip),这可能会迫使你立即重做大部分代码。