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

Getting TypeError: Error #1009; but wrecking brains on why it is going wrong.

Community Beginner ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

I am wrecking my brains, I am creating an animation and have some simple AS3 code but I honestly cannot see what I am doing wrong. This is the error I get below:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at animationno2V2_fla::MainTimeline/frame1()

I have attached the hyperlink access to the code on my google drive:

animation no2V2.fla - Google Drive

animation no2V2.swf - Google Drive

please help.

Thank you.

TOPICS
ActionScript

Views

389

Translate

Translate

Report

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

Advisor , Jan 15, 2018 Jan 15, 2018

First of all remove all the code on Frame 1 and add the name "Main" into the class field on your FLA propery, then

add this code:

//////////////////////////////

package {

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    import flash.events.Event;

    import flash.display.SimpleButton;

    public class Main extends MovieClip {

        public var first_btn:SimpleButton;

        public var second_btn:SimpleButton;

        public var third_btn:SimpleButton;

      

        public funct

...

Votes

Translate

Translate
Community Expert ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

click file>publish settings>swf and tick 'permit debugging'.  retest.

the problematic line number that references a non-existent object will be in the error message.

Votes

Translate

Translate

Report

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
Advisor ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

First of all remove all the code on Frame 1 and add the name "Main" into the class field on your FLA propery, then

add this code:

//////////////////////////////

package {

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    import flash.events.Event;

    import flash.display.SimpleButton;

    public class Main extends MovieClip {

        public var first_btn:SimpleButton;

        public var second_btn:SimpleButton;

        public var third_btn:SimpleButton;

      

        public function Main(){

            addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);

        }

      

        private function addedToStageHandler(event:Event):void{

            try{

                first_btn.addEventListener(MouseEvent.CLICK,startAnimation);

                second_btn.addEventListener(MouseEvent.CLICK,middleAnimation);

                third_btn.addEventListener(MouseEvent.CLICK,endAnimation);

            }catch(event:*){

                trace("runtime error!");

            }

        }

        private function startAnimation(event:MouseEvent):void{

            gotoAndPlay("start");

        }

      

        private function middleAnimation(event:MouseEvent):void{

            gotoAndPlay("middle");

        }

      

        private function endAnimation(event:MouseEvent):void{

            gotoAndPlay("end");

        }

    }

}

/////////////////////////////////

after copy and paste your 3 buttons of the frame "start"

to the frame 1 and make them invisible. You error come by the fact that

every element of your scene must exist on the first frame if you declare it on the first frame.

that's it

Votes

Translate

Translate

Report

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 Beginner ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

Thank you Robert Mc Dowell, I now know what I did wrong, you have been helpful.

I have been meaning to integrate object oriented code and I will do this.

Thank you again.

Votes

Translate

Translate

Report

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
Advisor ,
Jan 15, 2018 Jan 15, 2018

Copy link to clipboard

Copied

LATEST

you are welcome.

> I have been meaning to integrate object oriented code and I will do this.

OOP is much more complex, a good habit to separate design with code is a must

to not be in trouble. The compiler is much more accurate when the code is on a file

and can be more explicit when an error occurs.

thanks for your mention

Votes

Translate

Translate

Report

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