5 Replies Latest reply on Sep 9, 2010 10:28 AM by Ned Murphy

    Dont understand what is wrong in code

    Zhdesigner Level 1

      Task of my code that movieclip added on stage, change its size - height when change size of browsers(player) window thus height movieclip = height rowsers(player) window.

      That is my code:

       

      package
      {
      import flash.display.*;
      import flash.display.Sprite;
      import flash.display.StageAlign;
      import flash.display.StageScaleMode;
      import flash.events.Event;

       

      public class ZhMenu extends Sprite
      {
      public var menubg:MovieClip;

       

      public function ZhMenu()
      {
      var menubg:  = new menuGrad();
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;
      stage.addEventListener(Event.RESIZE, onResize);
      this.addChild (menubg);
      menubg.x=0;
      menubg.width = 150;
      menubg.height = stage.stageHeight;
      }

       


      public function onResize (event:Event):void
      {
      var sh:Number = stage.stageHeight;
      menubg.x=0;
      menubg.width=150;
      menubg.height=sh;
      }
      }
      }

       

      In the issue MovieClip menubg added on stage but when i change size of window i get error:

      TypeError: Error #1009: It is not possible to cause property or a method referring to object "null".
      at ZhMenu/onResize()

      And menubg dont change its size of course.

       

      I dont understand what is wrong.

      Plize help me if u know Action Script 3.0 better.

        • 1. Re: Dont understand what is wrong in code
          Ned Murphy Adobe Community Professional & MVP

          I do not know if this will resolve the error, but in your ZhMenu function you declare another mwnubg object ( var menubg:  = new menuGrad(); ), which will only have scope within that function.  The one you declare ( public var menubg:MovieClip; ) outside is never instantiated, and that is the one that your onResize function is trying to modify.

           

          As far as the error goes, go into your Flash Publish Settings and select the option to Permit Debugging.  When you run the file again, there may be a number provided in the error message indicating which line is causing the problem.

          • 2. Re: Dont understand what is wrong in code
            Zhdesigner Level 1

            in function onResize the line menubg.x=0; cause the error, but i still dont know why

            • 3. Re: Dont understand what is wrong in code
              Ned Murphy Adobe Community Professional & MVP

              Because you do not have an instance of the object... open a new fla and try these lines...

               

              // this will fail

              var menubg:MovieClip;
              menubg.x = 0;

               

              // this will not fail

              var menubg2:MovieClip = new MovieClip();
              menubg2.x = 0;

              1 person found this helpful
              • 4. Re: Dont understand what is wrong in code
                Zhdesigner Level 1

                YYYEEEEESSSSSS!!!!!!  New code  is work:

                package
                {
                    import flash.display.*;
                    import flash.display.Sprite;
                    import flash.display.StageAlign;
                    import flash.display.StageScaleMode;
                    import flash.events.Event;

                 

                    public class ZhMenu extends Sprite
                    {
                        public var menubg:MovieClip;
                       
                        public function ZhMenu()
                        {
                        var menubg:MovieClip = new menuGrad();
                            stage.scaleMode = StageScaleMode.NO_SCALE;
                            stage.align = StageAlign.TOP_LEFT;
                            stage.addEventListener(Event.RESIZE, onResize);
                        this.addChild (menubg);
                        menubg.x=0;
                        menubg.width = 150;
                          menubg.height = stage.stageHeight;
                        }

                 

                        public function onResize (event:Event):void
                          {
                        var menubg2:MovieClip = new menuGrad();   
                        var sh:Number = stage.stageHeight;
                        menubg2.x=0;
                        menubg2.width=150;
                        menubg2.height=sh;
                        this.addChild (menubg2);
                          }
                    }
                }

                 

                BIG THANKS Ned Murphy

                I very gratitude.

                • 5. Re: Dont understand what is wrong in code
                  Ned Murphy Adobe Community Professional & MVP

                  You're welcome