Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error # 1120, Access of undefined property ERROR. AS3

Explorer ,
Apr 11, 2014 Apr 11, 2014

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!

TOPICS
ActionScript
6.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 11, 2014 Apr 11, 2014

The big problem is this line:

public function Game();

Remove semicolon and try to compile again.

Translate
Community Expert ,
Apr 11, 2014 Apr 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();         }      

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 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;

            }

        }

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2014 Apr 11, 2014

does your library symbol have class, Square?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

Idk what you mean, but the AS linkage of my Square is to Square

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

Would it help if I were to upload my files? All it is is the Square.as , Game.as, blank stage, and the Square library picture...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2014 Apr 11, 2014

in your fla, click file>publish settings>swf>tick 'permit debugging'.  retest.

copy and paste the complete error message.

copy and paste your corrected document class.

bold the line number mentioned at the top of the error message.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2014 Apr 11, 2014

create a new directory.

save your fla and both those class files into the new directory.

retest.

p.s.

private function timerListener(e:TimerEvent):void
        {
            square.edgeCorrect;
        }

should be

private function timerListener(e:TimerEvent):void
        {
            square.edgeCorrect();
        }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

I changed the directory and the code that you changed above, but no luck, the errors now just are the same, but with a different directory now. I have one question, under publish settings --> Script "Actionscript 3.0" --> Settings of the script, all of the 3 boxes are checked, but underneath in the source path, i have one that says "./classes/". Is that correct? After all i have tried, thats the only thing i can think of.

I unchecked strict mode, but the file size increase 45000% and my system is shutting down, it crashed a system file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2014 Apr 11, 2014

source path should be "." only.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

I changed it to that, same errors.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 11, 2014 Apr 11, 2014

copy and paste the error messages.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

C:\Documents and Settings\g.GLAPTOP\Desktop\Flash apps\Color Clicker\Color Clicker\Game.as, Line 15

1120: Access of undefined property square.

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

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

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

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

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

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

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

The directory change is that i added a folder: "Color Clicker" inside of "Color Clicker".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

To all who may be able to help, this is still not solved. 😕

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 11, 2014 Apr 11, 2014

On closer inspection, it looks like "call to possibly undefined method addChild means there's a problem compiling at even the lower level. Count your open and close braces and make sure they all match--in the code sample you posted at the top, they don't.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

I did, i have 5 opening & closing brackets, another person on a different forum said that it looks like the constructor is terminating before it reads the body?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 11, 2014 Apr 11, 2014

The big problem is this line:

public function Game();

Remove semicolon and try to compile again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

Thankyou SO MUCH! i have spent 3 days unable to develop my application due to a stray semicolon? I really appreciate your comment, but now i just have one small problem, the width and height of my spawned square is 0, which by my method of calculating the height, is impossible. Here is my method of calculating height and width:

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

            if (height == 0) {height = 50}

            width = height;

So in my input, how is it displaying my height and width as 0?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 11, 2014 Apr 11, 2014

This line of code is in constructor - unless there are display objects on display list - dimensions will be 0/0 no matter if you set them or not.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

How would i fix this? This line of code is in my other AS file btw, here is the full 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);

            if (height == 0) {height = 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;

            }

        }

    }

}

This worked just fine before the topic of this question's error came about.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 11, 2014 Apr 11, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 11, 2014 Apr 11, 2014

You need to have something on Square timeline in order to manipulate width/height. If there is nothing on timeline - what is the meaning of width/height? Dimensions of nothing is nothing (zero), right?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 11, 2014 Apr 11, 2014

The reason i have nothing on my timeline, is because i want to spawn that object from my library, are you suggesting that I manually place Square on my stage, and have it be manipulated once the game starts?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines