Flash 函数作为构造函数执行,但不作为函数执行
我的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; } } } 包装{ 导入flash.display.MovieClip; 公共类FigureConstruct扩展了MovieClip{ 公共函数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; var figure:FigureConstruct = new FigureConstruct(); stage.addChild(figure); figure.sizeFigure(); figure.x = stage.stageWidth/2; figure.y = stage.stageHeight/2; 变量figure:FigureConstruct=newfigureconstruct(); stage.addChild(图); 图x=阶段宽度/2; 图y=阶段高度/2; 这些文件位于同一目录中。在我的FLA库中,我有我的figure MovieClip,它有一个“FigureConstruct”类和一个“flash.display.MovieClip”基类 目前,上面的代码运行良好,因为我发现,如果我将对象大小代码作为构造执行(使用文件名作为函数名),它就可以工作 我最初打算在AS文件中使用名为“sizeFigure()”的函数,然后在FLA的第1帧上的“stage.addChild(figure);”之后调用“figure.sizeFigure();” 这个输出 错误#1006:值不是函数 有人能解释一下我缺少了什么来让它作为函数而不是构造函数执行吗 当我为库对象设置类指针和基类指针时,我想我可能是搞错了。。。但不确定 PS-抱歉,如果我误用了这些术语,在我走的时候仍然把它们钉牢 编辑:下面是在我将函数名更改为文件名,使其成为类构造函数之前似乎不起作用的原始代码。以上版本有效,以下版本无效 display和move.as package { import flash.display.MovieClip; public class FigureConstruct extends MovieClip { public function sizeFigure() { this.height = stage.stageHeight/5; this.width = stage.stageWidth/5; } } } 包装{ 导入flash.display.MovieClip; 公共类FigureConstruct扩展了MovieClip{ 公共函数sizeFigure(){ this.height=stage.stageHeight/5; this.width=stage.stageWidth/5; } } } displayandmove.fla: var figure:FigureConstruct = new FigureConstruct(); stage.addChild(figure); figure.x = stage.stageWidth/2; figure.y = stage.stageHeight/2; var figure:FigureConstruct = new FigureConstruct(); stage.addChild(figure); figure.sizeFigure(); figure.x = stage.stageWidth/2; figure.y = stage.stageHeight/2; 变量figure:FigureConstruct=newfigureconstruct(); stage.addChild(图); figure.sizeFigure(); 图x=阶段宽度/2; 图y=阶段高度/2;Flash 函数作为构造函数执行,但不作为函数执行,flash,actionscript-3,Flash,Actionscript 3,我的displayandmove.as文件中有以下代码: package { import flash.display.MovieClip; public class FigureConstruct extends MovieClip { public function displayandmove() { this.height = stage.stageHeight/5; this.width = stag
这很管用,我和你一样把它设置好了
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;
}
}
}
错误#1006:值不是函数
这发生在代码的其他地方。该类是否具有名为
值
的属性(函数get/set)?您是否正在尝试将其作为函数访问?检查代码中的value()
并将其替换为value
我将代码添加到了我的原始帖子中,当时我正试图使用类中的方法来调整对象的大小。您的意思是()可能需要删除吗?这是我当前正在使用的所有代码。公共类FigureConstruct
必须在FigureConstruct.as
中声明,而不是在displayandmove.asPerfect中声明,这是有效的。一旦我更改了AS文件名以匹配指定的类,我就能够以sizeFigure()的形式运行该函数。对我来说,这连接了好几个点。公共类
应该始终在文件中声明为
文件,并且与类的名称完全相同。当我贴出答案时,不知何故我忽略了一个事实,那就是名字不匹配。