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

How to fix this error

New Here ,
Aug 05, 2012 Aug 05, 2012

Copy link to clipboard

Copied

i want to load external swf but it's give me error

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

    at Main()

the code is

package{

   

    import flash.display.Sprite;

    import flash.events.MouseEvent;

    import flash.net.navigateToURL;

    import flash.net.URLRequest;

    import flash.display.Loader;

    public class Main extends Sprite{

       

        private var _loader:Loader = new Loader();

       

        public function Main():void{

            mc_star.addEventListener(MouseEvent.CLICK,buttonClick);

            mc_gear.addEventListener(MouseEvent.CLICK,buttonClick);

            mc_apple.addEventListener(MouseEvent.CLICK,buttonClick);

            mc_photo.addEventListener(MouseEvent.CLICK,buttonClick);

            mc_buy.addEventListener(MouseEvent.CLICK,buttonClick);

            mc_contact.addEventListener(MouseEvent.CLICK,buttonClick);

            _loader=new Loader();

            addChild(_loader);

        }

       

        private function buttonClick(e:MouseEvent):void{

            var url:URLRequest=new URLRequest();

            switch(e.target.name){

                case "mc_star": url.url="bg2.swf"; break;

                case "mc_gear": url.url="bg3.swf"; break;

                case "mc_apple": url.url="bg4.swf"; break;

                case "mc_photo": url.url="bg5.swf"; break;

                case "mc_buy": url.url="bg6.swf"; break;

                case "mc_contact": url.url="bg7.swf"; break;

            }

            _loader.load(url);

        }

    }   

}

TOPICS
ActionScript

Views

1.4K

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

Community Expert , Aug 06, 2012 Aug 06, 2012

click file/publish settings/swf and tick "permit debugging".  retest.

the line number with the null object will be in the error message.  that will probably be one of your mc_ objects.

when you find which, return to your fla's stage and click the object you think should have that instance name and fix the problem.

Votes

Translate

Translate
Community Expert ,
Aug 05, 2012 Aug 05, 2012

Copy link to clipboard

Copied

use:

package{

   

    import flash.display.Sprite;

    import flash.events.MouseEvent;

    import flash.net.navigateToURL;

    import flash.net.URLRequest;

    import flash.display.Loader;

    public class Main extends Sprite{

       

        private var _loader:Loader = new Loader();

       

        public function Main():void{

            mc_star.addEventListener(MouseEvent.CLICK,buttonClick);

            mc_gear.addEventListener(MouseEvent.CLICK,buttonClick);

            mc_apple.addEventListener(MouseEvent.CLICK,buttonClick);

            mc_photo.addEventListener(MouseEvent.CLICK,buttonClick);

            mc_buy.addEventListener(MouseEvent.CLICK,buttonClick);

            mc_contact.addEventListener(MouseEvent.CLICK,buttonClick);

            //_loader=new Loader();

            addChild(_loader);

        }

       

        private function buttonClick(e:MouseEvent):void{

            var url:URLRequest=new URLRequest();

            switch(e.target.name){

                case "mc_star": url.url="bg2.swf"; break;

                case "mc_gear": url.url="bg3.swf"; break;

                case "mc_apple": url.url="bg4.swf"; break;

                case "mc_photo": url.url="bg5.swf"; break;

                case "mc_buy": url.url="bg6.swf"; break;

                case "mc_contact": url.url="bg7.swf"; break;

            }

            _loader.load(url);

        }

    }   

}

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
New Here ,
Aug 06, 2012 Aug 06, 2012

Copy link to clipboard

Copied

Thank you for your help

but it's give the same error

you can take look at it

http://mir.cr/0BJTHHF4

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 Expert ,
Aug 06, 2012 Aug 06, 2012

Copy link to clipboard

Copied

click file/publish settings/swf and tick "permit debugging".  retest.

the line number with the null object will be in the error message.  that will probably be one of your mc_ objects.

when you find which, return to your fla's stage and click the object you think should have that instance name and fix the problem.

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
New Here ,
Aug 06, 2012 Aug 06, 2012

Copy link to clipboard

Copied

Thank you again for your help

all of this have a instance name

it's give me this error

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

    at Main()

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 Expert ,
Aug 06, 2012 Aug 06, 2012

Copy link to clipboard

Copied

which is line 23?

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
New Here ,
Aug 06, 2012 Aug 06, 2012

Copy link to clipboard

Copied

  mc_star.addEventListener(MouseEvent.CLICK,buttonClick);

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 Expert ,
Aug 06, 2012 Aug 06, 2012

Copy link to clipboard

Copied

mc_star doesn't exist.

return to your fla's stage and click the object you think is mc_star and fix the problem.

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
New Here ,
Aug 09, 2012 Aug 09, 2012

Copy link to clipboard

Copied

Thank you i fix the problem

you a great man

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 Expert ,
Aug 09, 2012 Aug 09, 2012

Copy link to clipboard

Copied

LATEST

you're welcome.

p.s.  please mark helpful/correct responses.

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