7 Replies Latest reply: Apr 18, 2011 1:14 AM by barpos RSS

    Bogus error?

    barpos Community Member

      My code runs fine, but nonetheless I keep getting the following error message in the output panel:

       

      ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

        • 1. Re: Bogus error?
          Ned Murphy CommunityMVP

          There is not likely anything bogus about the error.  Not much anyone can do to help with the info given though.

          • 2. Re: Bogus error?
            barpos Community Member

            // Snow Blade button handlers
            // --------------------------------------------------
            function snowBladeOverHandler(event:MouseEvent):void
            {
                // enable RollingTractor movie clip;
                var tractorClip:MovieClip = new scrollTractor();
                tractorClip.x = 0;
                tractorClip.y = browserHeight;
                addChild(tractorClip);

             

                function snowBladeOutHandler(event:MouseEvent):void
                {
                    // disable RollingTractor movie clip;
                    removeChild(tractorClip);             // *** THIS IS WHAT TRIGGERS THE ERROR, BUT THE MC GETS REMOVED REGARDLESS ***
                }
                SnowBlade_Btn.addEventListener(MouseEvent.MOUSE_OUT, snowBladeOutHandler);

             

                function snowBladeClickHandler(event:MouseEvent):void
                {
                    // do something here ...
                }
                SnowBlade_Btn.addEventListener(MouseEvent.CLICK, snowBladeClickHandler);
            }
            SnowBlade_Btn.addEventListener(MouseEvent.MOUSE_OVER, snowBladeOverHandler);

            • 3. Re: Bogus error?
              Andrei1 Community Member

              First, I have noticed that you use nested functions a lot although on numerous occasions in responses to your posts other guys made compelling cases against nested functions. What you observe now with this error is partially a result of using nested functions.

               

              Of course it is up to you to employ subpar practices and continue encountering difficulties.

               

              Second, the code is quite inefficient because you strain Flash with adding event listeners when it is good enough to add them once. It also looks like it is enough to create tractor once as well and reuse the same instance.

               

              Your code should be something like this:

               

              var tractorClip:MovieClip = new scrollTractor();
              tractorClip.x = 0;
              tractorClip.y = browserHeight;
              
              SnowBlade_Btn.addEventListener(MouseEvent.MOUSE_OUT, snowBladeOutHandler);
              SnowBlade_Btn.addEventListener(MouseEvent.CLICK, snowBladeClickHandler);
              SnowBlade_Btn.addEventListener(MouseEvent.MOUSE_OVER, snowBladeOverHandler);
              
              function snowBladeOverHandler(event:MouseEvent):void {
                   // enable RollingTractor movie clip;
                   addChild(tractorClip);
              }
              
              function snowBladeOutHandler(event:MouseEvent):void {
                   if(this.contains(tractorClip)) removeChild(tractorClip);
              }
              
              function snowBladeClickHandler(event:MouseEvent):void {
                   // do something here ...
              }
              
              • 4. Re: Bogus error?
                barpos Community Member

                On numerous occasions?  I think you are mistaking me with somebody else.

                 

                The reason I nested those listeners is because I was getting an error otherwise.  But, since you condionally added the contains() function, that takes care of it. <s>

                 

                Thanks for you help ...

                 

                Regards,

                 

                Ron

                • 5. Re: Bogus error?
                  barpos Community Member

                  I just tried your code, and I had to modify it a bit otherwise the animation was out of whack (starting at the wrong place (center instead of X 0) and subsequent mouse overs didn't work).  Also, if I comment out the removeChild(0 line, and the user repeatedly mouse out and over, he/she gets to see multiple tractors at once, at different stage of playing.  Nice effect!  I don't understand how Flash player can handle multiple instances at once though since it is the same instance name (tractorClip) we're talking about here.

                   

                  var tractorClip:MovieClip;
                  SnowBlade_Btn.addEventListener(MouseEvent.MOUSE_OUT, snowBladeOutHandler);
                  SnowBlade_Btn.addEventListener(MouseEvent.CLICK, snowBladeClickHandler);
                  SnowBlade_Btn.addEventListener(MouseEvent.MOUSE_OVER, snowBladeOverHandler);

                   

                  function snowBladeOverHandler(event:MouseEvent):void
                  {
                      // enable RollingTractor movie clip;
                      tractorClip = new scrollTractor();
                      tractorClip.x = 0;
                      tractorClip.y = buildingBottom;
                      addChild(tractorClip);
                  }

                   

                  function snowBladeOutHandler(event:MouseEvent):void
                  {
                      // if(this.contains(tractorClip)) removeChild(tractorClip);
                  }

                   

                  function snowBladeClickHandler(event:MouseEvent):void
                  {
                      // do something here ...
                  }

                  • 6. Re: Bogus error?
                    Andrei1 Community Member

                    I am not sure why you need to create new instances in snowBladeOverHandler. Wouldn't one instance be enough? Like:

                     

                    var tractorClip:MovieClip = new scrollTractor();
                    // ....
                    function snowBladeOverHandler(event:MouseEvent):void
                    {
                         tractorClip.x = 0;
                         tractorClip.y = buildingBottom;
                         addChild(tractorClip);
                    }
                    

                     

                    The way it is done now - every time on roll over new instance is created and added to display list. Eventually Flash will hit a wall in terms of memory consumption.

                     

                    "I don't understand how Flash player can handle multiple instances at once though since it is the same instance name (tractorClip) we're talking about here."

                     

                    There is a distinct difference between variable and it's value. When you create a variable  - you create a reference (pointer) to it in memory. Then when you use new scrollTractor - you actually create a new variable with its own pointer. The fact that you use equate one variable to a new one is just assigning references. You can have unlimited references to the same instance. If a single reference to instance exists - it will never be removed from memory.

                     

                    In your case you add instance to display list and, effectively, create another reference.

                     

                    " Nice effect! "

                     

                    It may be but, again, the way it is done is uncontrollable and if you like it - you should reconsider how you handle memory issues in conjunction with this effect.

                    • 7. Re: Bogus error?
                      barpos Community Member

                      >I am not sure why you need to create new instances in snowBladeOverHandler. Wouldn't one instance be enough?<

                       

                      Well, if the user wants to redisplay the scrolling tractor, that's the way to go.  For whatever reason, your code starts displaying the tractor at about x:960 instead of coded x:0.  So, something was bugging anyhow.

                       

                      >The  way it is done now - every time on roll over new instance is created  and added to display list. Eventually Flash will hit a wall in terms of  memory consumption.<

                       

                      I understand that.  Perhaps, I could add a counter to counter (max. 3 instances) this possible problem.

                       

                      >In your case you add instance to display list and, effectively, create another reference.<

                      Thanks for the info.

                       

                      >It  may be but, again, the way it is done is uncontrollable and if you like  it - you should reconsider how you handle memory issues in conjunction  with this effect.<

                       

                      Hmmm, is there a way to detect the user memory capacity during runtime?

                       

                      Regards,

                       

                      Ron