0
votes

I started a new AS3 document today in Flash CC. My stage was empty. I made the document class a .as file called test.as - my .fla was also called test.fla.

So I created a movieclip called mirror and gave it a AS3 linkage name of mirror. I put it in my library and deleted it from the stage. Then I went to my external .as file and wrote this:

package  {

    import flash.display.MovieClip;
    import flash.events.MouseEvent;


    public class test extends MovieClip {

        public var mirror1:MovieClip = new mirror();

        public function dragMirror1(event:MouseEvent):void
        {
            mirror1.startDrag();
        }
        public function releaseMirror1(event:MouseEvent):void
        {
            mirror1.stopDrag();
        }
        mirror1.addEventListener(MouseEvent.MOUSE_DOWN,dragMirror1);
        mirror1.addEventListener(MouseEvent.MOUSE_UP,releaseMirror1);
    }

}

This seemed perfectly harmless code, but when I ran the code I got four errors:

C:\Users\Raphael\Creative Cloud Files\LightStage\Testing\test.as, Line 20, Column 48    1120: Access of undefined property releaseMirror1.
C:\Users\Raphael\Creative Cloud Files\LightStage\Testing\test.as, Line 20, Column 3 1120: Access of undefined property mirror1.
C:\Users\Raphael\Creative Cloud Files\LightStage\Testing\test.as, Line 19, Column 50    1120: Access of undefined property dragMirror1.
C:\Users\Raphael\Creative Cloud Files\LightStage\Testing\test.as, Line 19, Column 3 1120: Access of undefined property mirror1.

Does anyone have any idea why this is happening? Maybe I'm missing something basic, but I've created a few new .fla and .as files to test this and it keeps happening, even when I rewrite the code and use different AS3 linkage names.

1

1 Answers

0
votes

To avoid these errors, you have to use your mirror1.addEventListener() inside the constructor of your class after adding your mirror object to your stage :

public class Test extends MovieClip {

    public var mirror1:MovieClip = new mirror();

    public function Test():void 
    {
        addChild(mirror1);
        mirror1.addEventListener(MouseEvent.MOUSE_DOWN, dragMirror1);
        mirror1.addEventListener(MouseEvent.MOUSE_UP, releaseMirror1);
    }
    public function dragMirror1(event:MouseEvent):void
    {
        mirror1.startDrag();
    }
    public function releaseMirror1(event:MouseEvent):void
    {
        mirror1.stopDrag();
    }

}

Hope that can help.