Skip navigation
mido_0
Currently Being Moderated

How to fix this error

Aug 5, 2012 4:59 PM

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);

        }

    }   

}

 
Replies
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 5, 2012 6:02 PM   in reply to mido_0

    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);

            }

        }   

    }

     
    |
    Mark as:
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 6, 2012 9:38 AM   in reply to mido_0

    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.

     
    |
    Mark as:
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 6, 2012 12:04 PM   in reply to mido_0

    which is line 23?

     
    |
    Mark as:
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 6, 2012 4:48 PM   in reply to mido_0

    mc_star doesn't exist.

     

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

     
    |
    Mark as:
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 9, 2012 10:06 AM   in reply to mido_0

    you're welcome.

     

    p.s.  please mark helpful/correct responses.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points