java 不执行构造函数_函数作为构造函数执行,但不作为函数执行
我在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(figure);”之后在我的FLA的第1幀 .
這個輸出
錯誤#1006:值不是函數 .
任何人都可以解釋我缺少什么來讓它作為一個函數而不是作為構造函數執行?
我想也許當我為庫對象設置我的類和基類指針時我會搞砸......但不確定 .
PS - 對不起,如果我濫用條款,仍然在我去的時候把它們釘死 .
Edit: Below is the original code that does not seem to work until after I changed the name of my function to the name of the file, making it the class constructor. The above version works, below does not.
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;
總結
以上是生活随笔為你收集整理的java 不执行构造函数_函数作为构造函数执行,但不作为函数执行的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 光大绿色零碳信用卡年费多少
- 下一篇: 幻世机器人_2014年科幻动作《幻世追踪