2009-10-18 109 views
0

我在displayandmove.as下面的代碼:功能執行的構造,但不作爲功能

 
package { 

    import flash.display.MovieClip; 

    public class FigureConstruct extends MovieClip { 

     public function displayandmove() { 
      this.height = stage.stageHeight/5; 
      this.width = stage.stageWidth/5; 
     } 

    } 

} 

而且我displayandmove.fla的第1幀我有以下幾點:

 
var figure:FigureConstruct = new FigureConstruct(); 
stage.addChild(figure); 
figure.x = stage.stageWidth/2; 
figure.y = stage.stageHeight/2; 

這些文件位於相同的目錄中。在我的FLA庫中,我有我的圖形MovieClip,它具有一類「FigureConstruct」和基類「flash.display.MovieClip」。

目前上面的代碼工作正常,因爲我想如果我執行對象大小代碼作爲構造 - 使用文件名作爲函數名稱 - 它的工作原理。

我最初打算做的是在我的AS文件中使用名爲「sizeFigure()」的函數,然後調用「figure.sizeFigure();」後「stage.addChild(圖);」在我的FLA的第1幀上。

此輸出「錯誤#1006:值不是函數。」

任何人都可以解釋我缺少什麼讓它作爲一個函數而不是作爲構造函數執行嗎?

我以爲也許我瘋狂了,當我設置我的類和基類指針庫對象...但不知道。

PS - 對不起,如果我濫用條款,仍然釘我下去的那些人。

編輯:下面是原來的代碼,直到我將我的函數的名稱更改爲文件的名稱後才起作用,使其成爲類構造函數。以上版本的作品,下面沒有。

displayandmove.as

 
package { 

    import flash.display.MovieClip; 

    public class FigureConstruct extends MovieClip { 

     public function sizeFigure() { 
      this.height = stage.stageHeight/5; 
      this.width = stage.stageWidth/5; 
     } 

    } 

} 

displayandmove.fla:

 
var figure:FigureConstruct = new FigureConstruct(); 
stage.addChild(figure); 
figure.sizeFigure(); 
figure.x = stage.stageWidth/2; 
figure.y = stage.stageHeight/2; 

回答

1

錯誤#1006:值不是一個函數

error發生別的地方在你的代碼。該類是否有名稱爲value的屬性(函數獲取/設置)?你是否試圖訪問它作爲一個函數?檢查您的代碼value()並用value替換它。

+0

我將代碼添加到我原來的帖子中,我只是想使用我的課堂中的方法來調整對象的大小。 你的意思是()的可能需要刪除?這是我目前正在使用的所有代碼。 – Structure 2009-10-18 06:05:57

+1

'public class FigureConstruct' **必須**在'FigureConstruct.as'中聲明,而不是在displayandmove.as中。 – Amarghosh 2009-10-18 06:38:25

+0

完美,工作。一旦我將AS文件名更改爲與指定的類匹配,我就可以像sizeFigure()那樣運行該函數。 這爲我連接了不少點。 – Structure 2009-10-18 07:01:42

0

這工作,我有它設置了像你有。

package { 

     import flash.display.MovieClip; 

     public class FigureConstruct extends MovieClip { 

      public function displayandmove():void 
      { 
       height = stage.stageHeight/5; 
       width = stage.stageWidth/5; 
      } 


      public function sizeFigure():void 
      { 
       x = stage.stageWidth/2; 
       y = stage.stageHeight/2; 
      } 
     } 
    }