1120:访问未定义的属性速度。

时间:2012-12-04 13:06:02

标签: actionscript-3 flash actionscript variables

我想更改位于另一个类中的var。 我得到了包含此代码的类c_wall.as:

package  {

import flash.display.MovieClip;
import flash.events.Event;


public class c_wall extends c_gameObject {
    public var speed:Number=10;

    public function c_wall() {








    }
    override public function update(){
        x-=speed;

    }
}

}

这个类是我的墙子的父级,它是一个在每帧10px的屏幕上移动的对象(我的var速度的值)

在主类中,我得到了以下代码来更改速度变量:

        Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

        faster.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler);

        function fl_TapHandler(event:TouchEvent):void
        {
            trace ("the speed has increased");
            speed++;//this is the speed he doesnt know

        }

现在我得到的错误是它不知道var speed

我认为解决方案是将var包含在update()中;功能。它在main中作为文件使用,如下所示:

                function onEnterFrame(evt:Event):void
                {

                    wall.update(;

                    player.update();


                } 

但我不会让它工作......有人知道解决方案吗?

问候, Merijn

1 个答案:

答案 0 :(得分:1)

如果要将TouchEvent侦听器保留在主类中,请删除它尝试访问speed变量的行。然后,在定义c_wall变量的speed类中,覆盖事件侦听器回调函数并操纵变量。

在主要课程中:

protected function fl_TapHandler(event:TouchEvent):void {
    //Do things relevant to the main class
}

c_wall课程中:

override protected function fl_TapHandler(event:TouchEvent):void {
    super.fl_TapHandler(event); //Pass along the event to the parent 
    speed++;
}

当然,如果你在主类中根本没有使用事件监听器,你总是可以将它从继承链中移到c_wall类并跳过覆盖。