Question

Hello dear Stackoverflowers! Here is my problem...

I'm trying to move some basic functionality for my object to external package.

I've got MovieClip item in my library with name mcUnit: which is actually a rectangle F8-ed in to Move Clip. I'm setting the AS Linkage to the package I want it to use: clGameUnit;

Here is part of the clGameUnit code:

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 ()
        {
        }

                ....
    }
}

And the error I get it:

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

Already tried everything. Even making the constructor send the object to the undefined property clGU:

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

And on the time line I call this Constructor manually:

var mcGameObj: clGameUnit = new clGameUnit (mcGUnit);

mcGUnit is the Instance name for the mcUnit instance that I assign it in properties. Here thing become even more complicated so I discarded this variant.

If there is a need to upload my project, will do so gladly!

Really need your help fellaz!

Was it helpful?

Solution

Put these lines into a function

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);

For example

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top