2014-09-02 87 views
-1

我遇到了使用trace()的问题;跟踪不能在Actionscript 3中使用Flash CS5

例如,在我的项目(和其他项目)中的多个点上,我有跟踪语句,直到最近才开始工作。出于某种原因,在之前工作过的相同项目中,跟踪不再在“输出”窗口中显示任何内容。

我已经确认并做了以下内容:

  1. 证明:对于输出滤波器是无或放牧
  2. 我发布预览到Flash,HTML不
  3. 在发布设置选项卡,“忽略跟踪动作”未被选中
  4. 已验证我通过双击Flashplayer窗口进行双击检查并看到“调试器”选项,从而验证了Flash Player调试器。
  5. 重置工作区,以防万一有什么奇怪的事情发生。
  6. 阅读StackOverflow中关于同一问题的其他3篇文章,尝试了每个人的解决方案,但尚未得到它的工作。

有没有人有任何想法?我添加了完整的代码。

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 
+1

您是否确定您追踪的线路已到达? – BadFeelingAboutThis 2014-09-02 22:35:23

+0

代码?简化,如果可能的话? – Craig 2014-09-03 02:10:50

+0

现在添加代码,这用于在输出中显示跟踪,现在不会,代码也没有更改。 @Craig – 2014-09-03 13:38:57

回答

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); 
+0

它不,仍然没有跟踪输出。 – 2014-09-04 14:14:46

+0

有趣。你可以跟踪另一个.fla文件中的任何东西吗?尝试设置一个新的.fla,没有外部代码,只需将trace(“我可以读这个”)写入actionscript(F9)面板。如果没有跟踪,请查看发布设置。在“高级”下,确保“忽略跟踪语句”未被选中。如果问题仍然存在,则会发送导致问题的最小代码。 – Craig 2014-09-04 16:50:44

+0

我无法追踪任何FLA中的任何内容。我创建了一个新的fla,并在动作选项卡中放置了跟踪(“hi”);仍然没有。 – 2014-09-04 20:55:44

0

首先

Main Class不正确写入。如果它已导入,则编译器应输出以下内容:error message

1114:公共属性只能在包内使用。

因为一个类的一般形式是:

package myPackage 
{ 
    class MyClass 
    { 
    } 
} 

在另一方面

具体来说,这error message不会发生,因为你没有可能导入了Main class

文件>动作设置>文档分类:Main

+0

我不明白,程序没有错误或警告。我现在已经把所有的代码放到了你的编译器中。 – 2014-09-04 16:08:28

+0

你还没有导入你的班级。您的'Main'类是否出现在“ActionScript设置”面板上?就像我说过的,如果这个类被导入,你的编译器应该输出一个错误信息,因为你的类没有被正确写入(包到一个包中)。 – helloflash 2014-09-04 16:13:12

+0

@Mark Rivinius - 如果您在未回答我的ActionScript Panel问题的情况下编辑您的问题(在我的评论之后添加软件包),将很难解决您的问题! – helloflash 2014-09-04 18:05:02

相关问题