0

你好亲爱的Stackoverflowers!这是我的问题...

我正在尝试将我的对象的一些基本功能移动到外部包。

我的库中有一个名为 mcUnit 的 MovieClip 项目:它实际上是一个矩形 F8-ed 以移动剪辑。我正在将 AS Linkage 设置为我希望它使用的包:clGameUnit;

这是 clGameUnit 代码的一部分:

package 
{
    import flash.display.MovieClip;
    import flash.geom.Point;
    import flash.events.MouseEvent;

    public class clGameUnit extends MovieClip
    {

            // Declaring all local object related variable
        var clGU:MovieClip = new MovieClip();
        var isOver:Boolean = false;

        // Declaring all global object related variable
        public var b_u_Selected:Boolean = false;
        public var p_u_Coordinates:Point = new Point();
        public var u_Image:int = 0;

        //Declaring all object related methods
        clGU.addEventListener (MouseEvent.CLICK, on_Object_LClick);
        clGU.addEventListener (MouseEvent.MOUSE_OVER, onObjectMouseOver);
        clGU.addEventListener (MouseEvent.MOUSE_OUT, onObjectMouseOut);
        clGU.addEventListener (MouseEvent.RIGHT_CLICK, on_Object_RClick);

        public function clGameUnit ()
        {
        }

                ....
    }
}

我得到它的错误:

1120: Access of undefined property clGU.
1120: Access of undefined property on_Object_LClick.
1120: Access of undefined property ... [other event listeners functions]

已经尝试了一切。甚至让构造函数将对象发送到未定义的属性 clGU:

public function clGameUnit (obj: MovieClip)
{
    clGU = obj;
}

在时间线上我手动调用这个构造函数:

var mcGameObj: clGameUnit = new clGameUnit (mcGUnit);

mcGUnit 是我在属性中为其分配的 mcUnit 实例的实例名称。这里的事情变得更加复杂,所以我放弃了这个变体。

如果有需要上传我的项目,会很乐意这样做!

真的需要你的帮助,伙计!

4

1 回答 1

1

将这些行放入一个函数中

clGU.addEventListener (MouseEvent.CLICK, on_Object_LClick);
clGU.addEventListener (MouseEvent.MOUSE_OVER, onObjectMouseOver);
clGU.addEventListener (MouseEvent.MOUSE_OUT, onObjectMouseOut);
clGU.addEventListener (MouseEvent.RIGHT_CLICK, on_Object_RClick);

例如

public function clGameUnit () {
    init();
}

private function init():void {
    clGU.addEventListener (MouseEvent.CLICK, on_Object_LClick);
    clGU.addEventListener (MouseEvent.MOUSE_OVER, onObjectMouseOver);
    clGU.addEventListener (MouseEvent.MOUSE_OUT, onObjectMouseOut);
    clGU.addEventListener (MouseEvent.RIGHT_CLICK, on_Object_RClick);
}
于 2013-08-26T05:15:49.617 回答