我遇到使用trace();
的问题例如,在我的项目(和其他项目)的多个点,我有跟踪语句,直到最近才起作用。由于某些原因,在之前工作的相同项目中,跟踪不再在“输出”窗口中显示任何内容。
我检查并完成了以下操作:
有没有人有任何想法?我添加了完整的代码。
package
{
//importing classes
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.events.Event;
//END importing classes
public class Main extends Sprite
{
//class level variables
private const FIELD_W:uint=9;
private const FIELD_H:uint=9;
private const NUM_MINES:uint=10;
private var mineField:Array=new Array();
private var game_container:Sprite=new Sprite();
private var tile:tile_movieclip;
private var timer:Timer=new Timer(1000);
private var toolbar:toolbar_mc;
private var gameOver:Boolean=false;
private var firstClick:Boolean=true;
private var remainingTiles:uint=FIELD_W*FIELD_H;
private var minesLeft:uint=NUM_MINES;
private var screenFrame:Screens;
//END class level variables
public function Main()
{
//Mine Field Creation
for (var i:uint=0; i<FIELD_H; i++)
{
mineField[i]=new Array();
for (var j:uint=0; j<FIELD_W; j++)
{
mineField[i].push(0);
}
}
trace("My dangerous mine field: "+mineField);
//END Mine Field Creation
addChild(game_container);
for (i=0; i<FIELD_H; i++)
{
for (j=0; j<FIELD_W; j++)
{
tile = new tile_movieclip();
game_container.addChild(tile);
tile.gotoAndStop(1);
tile.nrow=i;
tile.ncol=j;
tile.buttonMode=true;
tile.x=tile.width*j;
tile.y=tile.height*i;
tile.addEventListener(MouseEvent.CLICK,onTileClicked);
}
}
// end of tile creation
//time amangement and game over
toolbar = new toolbar_mc();
addChild(toolbar);
//var s_height:uint= stage.height;
toolbar.y=725;
timer.start();
timer.addEventListener(TimerEvent.TIMER,onTick);
//end of time management and game over
}//END Main function
private function onTick(e:TimerEvent):void
{
toolbar.message_text.text="Elapsed time: "+timer.currentCount+"s";
//trace("Elapsed time: "+timer.currentCount);
}
private function tileValue(row,col:uint):int
{
if (mineField[row]==undefined || mineField[row][col]==undefined)
{
return -1;
}
else
{
return mineField[row][col];
}
}
private function onTileClicked(e:MouseEvent):void
{
if (!gameOver && remainingTiles > 0)
{
var clicked_tile:tile_movieclip=e.currentTarget as tile_movieclip;
clicked_tile.removeEventListener(MouseEvent.CLICK,onTileClicked);
clicked_tile.buttonMode=false;
var clickedRow:uint=clicked_tile.nrow;
var clickedCol:uint=clicked_tile.ncol;
var clickedValue:uint=mineField[clickedRow][clickedCol];
if (firstClick)
{
firstClick=false;
//placing mines
var placedMines:uint=0;
var randomRow,randomCol:uint;
while (placedMines<NUM_MINES)
{
randomRow = Math.floor(Math.random()*FIELD_H);
randomCol = Math.floor(Math.random()*FIELD_W);
if (mineField[randomRow][randomCol] ==0)
{
if (randomRow!=clickedRow||randomCol!=clickedCol)
{
mineField[randomRow][randomCol] = 9;
placedMines++;
}
}
}//END placing Mines
// placing digits
for (var i:uint=0; i<FIELD_H; i++)
{
for (var j:uint=0; j<FIELD_W; j++)
{
if (mineField[i][j]==9)
{
for (var ii:int =-1; ii<=1; ii++)
{
for (var jj:int =-1; jj<=1; jj++)
{
if (ii!=0||jj!=0)
{
if (tileValue(i+ii,j+jj)!=9&&tileValue(i+ii,j+jj)!=-1)
{
mineField[i+ii][j+jj]++;
}
}
}
}
}
}
}
var debugString:String;
trace("My complete and formatted mine field: ");
for (i=0; i<FIELD_H; i++)
{
debugString="";
for (j=0; j<FIELD_W; j++)
{
debugString+=mineField[i][j]+" ";
}
trace(debugString);
}
// end of placing digits
// tile creation
}
if (e.shiftKey)
{
clicked_tile.gotoAndStop(5-clicked_tile.currentFrame);
remainingTiles--;
if (remainingTiles ==0)
{
timer.stop();
//Create a for loop involving string for number that appears on tiles
toolbar.message_text.text="WinBomb";
screenFrame = new Screens();
game_container.addChild(screenFrame);
screenFrame.gotoAndStop("win");
}
if (clickedValue ==9)
{
minesLeft--;
if (minesLeft==0)
{
timer.stop();
//Create a for loop involving string for number that appears on tiles
toolbar.message_text.text="Mine Free!!";
removeChild(toolbar);
screenFrame = new Screens();
game_container.addChild(screenFrame);
screenFrame.gotoAndStop("win");
}
}
}
else
{
//empty tile
if (clickedValue == 0)
{
floodFill(clickedRow,clickedCol);
}//END empty Tile
// numbered tile
if (clickedValue>0&&clickedValue<9)
{
clicked_tile.gotoAndStop(2);
clicked_tile.tile_text.text=clickedValue.toString();
remainingTiles--;
if (remainingTiles ==0)
{
toolbar.message_text.text="Mine Free!!";
removeChild(toolbar);
screenFrame = new Screens();
game_container.addChild(screenFrame);
screenFrame.gotoAndStop("win");
}
}// end of numbered tile
// mine
if (clickedValue==9)
{
clicked_tile.gotoAndStop(3);
timer.removeEventListener(TimerEvent.TIMER,onTick);
removeChild(toolbar);
screenFrame = new Screens();
game_container.addChild(screenFrame);
screenFrame.gotoAndStop("lose");
/*timer=new Timer(5000);
timer.start();
trace("Timer to End: "+timer.currentCount);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, loseScreen); screenFrame = new Screens();
*/
}// end of mine
}
}
else if (remainingTiles == 0)
{
timer.stop();
toolbar.message_text.text="Mine Free!!";
removeChild(toolbar);
screenFrame = new Screens();
game_container.addChild(screenFrame);
screenFrame.gotoAndStop("win");
}
}//END onTileClicked function
private function floodFill(row,col:uint):void
{
var emptyTile:tile_movieclip;
emptyTile=game_container.getChildAt(row*FIELD_W+col) as tile_movieclip;
if (emptyTile.currentFrame==1)
{
emptyTile.removeEventListener(MouseEvent.CLICK,onTileClicked);
emptyTile.buttonMode=false;
emptyTile.gotoAndStop(2);
if (mineField[row][col]>0)
{
emptyTile.tile_text.text=mineField[row][col].toString();
remainingTiles--;
}
else
{
emptyTile.gotoAndStop(5);
remainingTiles--;
}
if (mineField[row][col]==0)
{
for (var ii:int =-1; ii<=1; ii++)
{
for (var jj:int =-1; jj<=1; jj++)
{
if (ii!=0||jj!=0)
{
if (tileValue(row+ii,col+jj)!=9)
{
if (tileValue(row+ii,col+jj)!=-1)
{
floodFill(row+ii,col+jj);
}
}
}
}
}
}
}
}//END floodFill
/* private function loseScreen(e:TimerEvent)
{
timer.removeEventListener(TimerEvent.TIMER_COMPLETE, loseScreen);
game_container.addChild(screenFrame);
screenFrame.gotoAndStop("lose");
}*/
}//END Main CLass
}//END package
答案 0 :(得分:0)
查看代码的顶部,这是一个轻微的重新安排。在这个实验中,我冒昧地初始化你的'_FIELD'变量。试试吧。这会解决您的问题吗?
var mineField:Array = new Array;
var FIELD_H:int = 10;
var FIELD_W:int = 20;
for (var i:uint=0; i<FIELD_H; i++)
{
mineField[i]=new Array();
for (var j:uint=0; j<FIELD_W; j++)
{
mineField[i].push(0);
}
}
trace(mineField);
答案 1 :(得分:0)
<强>第一强>
您的Main Class
编写错误。如果已导入,则编译器应输出以下error message
:
1114:public属性只能在包中使用。
因为类的一般形式是:
package myPackage
{
class MyClass
{
}
}
另一方面
具体而言,由于您可能尚未导入error message
,因此未发生此Main class
:
档案&gt; ActionScript设置&gt;文件类:Main