Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 未定义属性的访问cerc_Actionscript 3_Compiler Errors - Fatal编程技术网

Actionscript 3 未定义属性的访问cerc

Actionscript 3 未定义属性的访问cerc,actionscript-3,compiler-errors,Actionscript 3,Compiler Errors,我在AS3中有以下代码: package clase { import flash.display.MovieClip; import flash.events.Event; /** * ... * @author cry */ public class CercNegru extends MovieClip { var growthRate:Number = 2; cerc.addEventL

我在AS3中有以下代码:

package clase
{
    import flash.display.MovieClip;
    import flash.events.Event;
    /**
     * ...
     * @author cry
     */
    public class CercNegru extends MovieClip
    {
        var growthRate:Number = 2;
        cerc.addEventListener(Event.ENTER_FRAME,grow);

        public function CercNegru() 
        {

        }
        private function grow(e:Event):void
        {
            trace("asdda");
        }
    }

}
运行此程序时收到错误:

    Line 12 1120: Access of undefined property cerc.
    Line 12 1120: Access of undefined property grow.
为了更好地理解,我放置了一个图像:

你能帮我解决这个问题吗


提前谢谢

错误是因为在类文件中,所有函数代码都需要存在于函数中

以这一行为例,它只是在类中浮动:

cerc.addEventListener(Event.ENTER_FRAME,grow);
public function CercNegru() 
{
    cerc.addEventListener(Event.ENTER_FRAME,grow);
}
然后进入构造函数(假设您希望在实例化类时立即运行该构造函数):

在类文件中,构造函数(其名称与类名完全匹配的函数)是get的名称,您可以使用
new
关键字

因此,执行
new CercNegru()
将调用该函数

现在,我还假设这个类文件附加到FlashPro库对象,并且时间线上有一个实例名为
cerc
。(如果不是这样,那么这就是您出错的原因)

不过,时间线的内容并不总是在构造函数中可用,因此您可能需要等待实例添加到屏幕上

public var cerc:MovieClip; //you may want to create a reference to the timeline item, so you get compile time checking

public function CercNegru() 
{
    this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}

private function addedToStage(e:Event):void {
    this.removeEventListener(Event.ADDED_TO_STAGE, addedToStage);

    //this is the equivalent of timeline code now

    cerc.addEventListener(Event.ENTER_FRAME,grow);
}
如错误所示,
cerc
未定义。所以你应该定义它。假设您的“cerc”是一个
精灵

var cerc:Sprite;

第二个错误被解决了。。。带“圆圈”的一个。你确定你将这个类附加到的时间线上有什么东西,实例名为
cerc
,并且它在第一个帧上吗?顺便说一句,为什么不将enter frame侦听器添加到
this
而不是
cerc
?唯一的区别是
e.target
在listeneryes中所指的内容……我认为这无关紧要,但我不知道goesSo是什么,你如何定义
cerc
?您发布文档类的代码是什么?链接到库对象?根据图像,
cerc
是一个
MovieClip
在您的舞台上,您只需放置
cerc.addEventListener(事件。进入_帧,增长)在你的
CercNegru
的构造函数中,正如@badfeelingabout在他的回答中告诉你的,不要忘记将你的
保存为
文件并重新编译…@Cristi-你明白了吗?
var cerc:Sprite;