Skip to main content
Inspiring
April 11, 2014
Answered

Error # 1120, Access of undefined property ERROR. AS3

  • April 11, 2014
  • 1 reply
  • 7177 views

I have a code inside of an actionscript file, and i receive multiple errors when attempting to debug:

1120: Access of undefined property square.

1180: Call to a possibly undefined method addChild.

1120: Access of undefined property square.

1120: Access of undefined property square.

1120: Access of undefined property fl_click.

1120: Access of undefined property myTimer.

1120: Access of undefined property timerListener.

1120: Access of undefined property myTimer.

Here is my code for my main actionscript file:

package

{

    import flash.events.MouseEvent;

    import flash.display.MovieClip;

    import flash.utils.Timer;

    import flash.events.TimerEvent;

    public class Game extends MovieClip

    {

        public var myTimer:Timer = new Timer(50);

        public var square:Square;

        square.addEventListener(MouseEvent.CLICK, fl_click);

        myTimer.addEventListener(TimerEvent.TIMER, timerListener);

        myTimer.start();

        private function timerListener(e:TimerEvent):void

        {

            square.edgeCorrect;

        }

        private function fl_click(event:MouseEvent):void

        {

            square.moveDownABit();

        }

        public function Game();

        {

            square = new Square();

            addChild( square );

        }

I am a beginner, so please tell me specifically what to do with my code, thanks!

This topic has been closed for replies.
Correct answer Andrei1-bKoviI

This is air for android, but that shouldn't matter, they were already ticked.

Game.as(the code you corrected for me) document class linked to FLA file in properties:

package

{

    import flash.events.MouseEvent;

    import flash.display.MovieClip;

    import flash.utils.Timer;

    import flash.events.TimerEvent;

    public class Game extends MovieClip

    {

        public var myTimer:Timer = new Timer(50);

        public var square:Square;

        public function Game();

        {

           square = new Square();

            addChild( square );

           square.addEventListener(MouseEvent.CLICK, fl_click);

           myTimer.addEventListener(TimerEvent.TIMER, timerListener);

            myTimer.start();

        };

        private function timerListener(e:TimerEvent):void

        {

            square.edgeCorrect;

        }

        private function fl_click(event:MouseEvent):void

        {

            square.moveDownABit();

        }

    }

}

Square.as, linked by AS linkage to Square in library:

package

{

    import flash.display.MovieClip;

    public class Square extends MovieClip

    {

        var score:Number = 0;

        var square_x:Number;

        var square_y:Number;

        public function Square()

        {

            height = Math.round(Math.random() * 160 + 50);

            width = height;

            square_x = Math.round(Math.random() * 385 + (width / 2));

            square_y = Math.round(Math.random() * 700 + (height / 2));

            x = square_x;

            y = square_y;

            trace("X:" + x, "Y:" + y, "Height and Width:" + height);

        }

        public function moveDownABit():void

        {

            trace("Object Clicked");

            height = Math.round(Math.random() * 160 + 50);

            width = height;

            square_x = Math.round(Math.random() * 480 + (width / 2));

            square_y = Math.round(Math.random() * 750 + (height / 2));

            if (x + (width/2) > 480)

            {

                x = x - 10;

            }

            if (y + (height/2) >700)

            {

                y = y - 10;

            }

            x = square_x;

            y = square_y;

            score = score + 1;

            trace(score);

        }

        public function edgeCorrect():void

        {

            if (x + (width/2) > 480)

            {

                x = x - 10;

            }

            if (y + (height/2) >700)

            {

                y = y - 10;

            }

        }

    }

}

Errors:

C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 151120: Access of undefined property square.

C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 161180: Call to a possibly undefined method addChild.

C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 161120: Access of undefined property square.

C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 181120: Access of undefined property square.

C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 181120: Access of undefined property fl_click.

C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 191120: Access of undefined property myTimer.

C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 191120: Access of undefined property timerListener.

C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Classes\Game.as, Line 201120: Access of undefined property myTimer.

Message was edited by: AngryGamerProductions


The big problem is this line:

public function Game();

Remove semicolon and try to compile again.

1 reply

kglad
Community Expert
April 11, 2014

is Game your document class?

if yes, you need something like:

package 
{
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    public class Game extends MovieClip
    {
        public var myTimer:Timer;
        public var square:Square;


   public function Game();
        {
               square = new Square();
               addChild( square );
               square.addEventListener(MouseEvent.CLICK, fl_click);
                myTimer = new Timer(50);
                  myTimer.addEventListener(TimerEvent.TIMER, timerListener);
                  myTimer.start();

         }
                 private function timerListener(e:TimerEvent):void         {
// this doesn't do anything useful
             square.edgeCorrect;         }         private function fl_click(event:MouseEvent):void         {             square.moveDownABit();         }      

Inspiring
April 11, 2014

No I still have all of the same errors . And yes, Game is my document class, i have had this problem for 3 days . Square is just a picture of a square in my library, i just have a blank stage, the game.as with the code you gave me above, and Square.as which has this code:

package

{

    import flash.display.MovieClip;

    public class Square extends MovieClip

    {

        var score:Number = 0;

        var square_x:Number;

        var square_y:Number;

        public function Square()

        {

            height = Math.round(Math.random() * 160 + 50);

            width = height;

            square_x = Math.round(Math.random() * 385 + (width / 2));

            square_y = Math.round(Math.random() * 700 + (height / 2));

            x = square_x;

            y = square_y;

            trace("X:" + x, "Y:" + y, "Height and Width:" + height);

        }

        public function moveDownABit():void

        {

            trace("Object Clicked");

            height = Math.round(Math.random() * 160 + 50);

            width = height;

            square_x = Math.round(Math.random() * 480 + (width / 2));

            square_y = Math.round(Math.random() * 750 + (height / 2));

            if (x + (width/2) > 480)

            {

                x = x - 10;

            }

            if (y + (height/2) >700)

            {

                y = y - 10;

            }

            x = square_x;

            y = square_y;

            score = score + 1;

            trace(score);

        }

        public function edgeCorrect():void

        {

            if (x + (width/2) > 480)

            {

                x = x - 10;

            }

            if (y + (height/2) >700)

            {

                y = y - 10;

            }

        }

    }

}

Inspiring
April 12, 2014

Do you have any graphics/objects on Square display list/timeline?


Im not sure what you mean by display list, but my stage/timeline are empty, and have not been edited since before, when it actually worked to scale them, i just have Square in my library, which is a square.