2014-01-24 36 views
0

我正在使用此代碼並獲取錯誤消息「1180:調用可能未定義的方法DirectBlock」。在Source:「block = new DirectBlock(lvlArray [i],(i-row * 22)* 25,row * 25);」我得到錯誤代碼「1180:調用DirectBlock可能未定義的方法」。

package{ 

import flash.display.MovieClip; 
import flash.events.*; 
public class EmptyBlock extends MovieClip{ 
    private var _root:MovieClip; 

    public function EmptyBlock(){ 
     this.addEventListener(Event.ADDED, beginClass); 
     this.addEventListener(Event.ENTER_FRAME, eFrameEvents); 
    } 
    private function beginClass(e:Event):void{ 
     _root = MovieClip(root); 

     this.buttonMode = true;//make this act like a button 
     this.addEventListener(MouseEvent.MOUSE_OVER, thisMouseOver); 
     this.addEventListener(MouseEvent.MOUSE_OUT, thisMouseOut); 
     this.addEventListener(MouseEvent.CLICK, thisClick); 
    } 
    private function eFrameEvents(e:Event):void{ 
     if(_root.gameOver){ 
      this.removeEventListener(Event.ENTER_FRAME, eFrameEvents); 
      this.removeEventListener(MouseEvent.MOUSE_OVER, thisMouseOver); 
      this.removeEventListener(MouseEvent.MOUSE_OUT, thisMouseOut); 
      this.removeEventListener(MouseEvent.CLICK, thisClick); 
      MovieClip(this.parent).removeChild(this); 
     } 
    } 
    private function thisMouseOver(e:MouseEvent):void{ 

     this.graphics.drawRect(0,0,25,25); 
     this.graphics.endFill(); 
    } 
    private function thisMouseOut(e:MouseEvent):void{ 

     this.graphics.beginFill(0x333333); 
     this.graphics.drawRect(0,0,25,25); 
     this.graphics.endFill(); 
    } 
    private function thisClick(e:MouseEvent):void{ 

    } 
} 
    } 

這是FLA文件:

stop(); 

//setting vars to step in for turns and special blocks 
var S:String = 'START'; 
var F:String = 'FINISH'; 
var U:String = 'UP'; 
var R:String = 'RIGHT'; 
var D:String = 'DOWN'; 
var L:String = 'LEFT'; 

var startDir:String; 
var finDir:String; 
var startCoord:int; 
var lvlArray:Array = new Array(); 

lvlArray = [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,R,1,1,D,0,0,R,1,1,D,0,0,R,1,1,D,0,0, 
      0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0, 
      0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0, 
      S,D,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,R,1,F, 
      0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0, 
      0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0, 
      0,R,1,1,U,0,0,R,1,1,U,0,0,R,1,1,U,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, 
      ]; 

//the names of these variables explain what they do 
var currentLvl:int = 1; 
var gameOver:Boolean = false; 

function startGame():void{ 
    //right now we don't have any code 
} 

var roadHolder:Sprite = new Sprite(); 
addChild(roadHolder); 
function makeRoad():void{ 
    var row:int = 0; 
    var block;//this will act as the block that we're placing down 
    for(var i:int=0;i<lvlArray.length;i++){//creating a loop that'll go through the level array 
     if(lvlArray[i] == 0){//if the current index is set to 0 
      block = new EmptyBlock();//create a gray empty block 
      block.graphics.beginFill(0x333333); 
      block.graphics.drawRect(0,0,25,25); 
      block.graphics.endFill(); 
      addChild(block); 
      //and set the coordinates to be relative to the place in the array 
      block.x= (i-row*22)*25; 
      block.y = row*25; 
     } else if(lvlArray[i] == 1){//if there is supposed to be a row 
      //just add a box that will be a darker color and won't have any actions 
      block = new Shape(); 
      block.graphics.beginFill(0x111111); 
      block.graphics.drawRect(0,0,25,25); 
      block.graphics.endFill(); 
      block.x= (i-row*22)*25; 
      block.y = row*25; 
      roadHolder.addChild(block);//add it to the roadHolder 
     } else if(lvlArray[i] is String){block 
      //then create a special block 
      block = new DirectBlock(lvlArray[i],(i-row*22)*25,row*25); 
      addChild(block); 
     } 
     for(var c:int = 1;c<=16;c++){ 
      if(i == c*22-1){ 
       //if 22 columns have gone by, then we move onto the next row 
       row++; 
      } 
     } 
    } 
} 
//run these functions at the start 
makeRoad(); 
startGame(); 
+2

DirectBlock類在哪裏?你目前沒有這方面的視野。您可能需要導入它,目前您正在收到該錯誤,因爲該類在您嘗試使用它的位置尚未提供。 –

回答

0

關過程中,你有沒有類調用DirectBlock和你EmptyBlock類是在構造函數沒有參數(如果你想用第二而不是第一個)。

相關問題