Skip to main content
deborahb44958436
Inspiring
March 9, 2015
Answered

why am I getting 1120: Access of undefined property ?

  • March 9, 2015
  • 1 reply
  • 1305 views

So I created this simple counter script to create a score board for a game.

import flash.events.MouseEvent;

redButton.addEventListener(MouseEvent.CLICK, randomOutput);

function randomOutput(e: MouseEvent): void {


  var count: Number = 0;

  count = count + 100;

  Counter.text = (count).toString();

}

It worked fine on the stage timeline. but when I transferred this code to ActionScript file I get the 1120 error on both redButton and Counter Instance Names. why? what am I doing wrong?

Here is the full code for the ActionScript file

package {

  import flash.display.MovieClip

  public class myScript1 extends MovieClip {

  public function myScript1() {

  // constructor code

  }

}

}

import flash.events.MouseEvent;

redButton.addEventListener(MouseEvent.CLICK, randomOutput);

function randomOutput(e: MouseEvent): void {

  var count: Number = 0;

  count = count + 100;

  Counter.text = (count).toString();

}

This topic has been closed for replies.
Correct answer moccamaximum

package

{

   

    import flash.display.MovieClip

    import flash.events.MouseEvent;

   

    public class myScript1 extends MovieClip

    {

       

        private var count:Number = 0;

       

        public function myScript1()

        {

       

            // constructor code

            //makes ure that there is a Button/MovieClip named "redButton" on stage in the first frame of the timeline

            redButton.addEventListener(MouseEvent.CLICK, randomOutput);

       

        }

       

       

       

        private function randomOutput(e:MouseEvent):void

        {

           

           

            count += 100;

            //make sure that there is a TextField named "Counter" on stage in the first frame of the timeline

            Counter.text = count;

       

        }

   

    }

}

1 reply

Inspiring
March 9, 2015

You have imports inside the class definition, those go outside the class, inside the package namespace like the first MovieClip one. Also, you cannot have code like redButton.addEventListener outside of a method - put that inside the constructor. Also, you are never going to have more than 100 points showing, since you set it to 0 each time you call randomOutput... which is not at all random.

deborahb44958436
Inspiring
March 9, 2015

Thanks dmennenoh. but can you give me a sample code to correct my script? since I'm a newbee  I'd take me forever to fully understand and fix it.

moccamaximumCorrect answer
Inspiring
March 10, 2015

package

{

   

    import flash.display.MovieClip

    import flash.events.MouseEvent;

   

    public class myScript1 extends MovieClip

    {

       

        private var count:Number = 0;

       

        public function myScript1()

        {

       

            // constructor code

            //makes ure that there is a Button/MovieClip named "redButton" on stage in the first frame of the timeline

            redButton.addEventListener(MouseEvent.CLICK, randomOutput);

       

        }

       

       

       

        private function randomOutput(e:MouseEvent):void

        {

           

           

            count += 100;

            //make sure that there is a TextField named "Counter" on stage in the first frame of the timeline

            Counter.text = count;

       

        }

   

    }

}