3 Replies Latest reply on Aug 26, 2010 12:52 PM by kglad

    onLoad working at _root level but not at mc_target level, why?

    atrzebunia

      I have two layers in my FLA both with empty movie clips as follows:

       

      In mc_Empty1, I attach a faded background movieclip as I wait for mc_Empty2 to load a SWF.  Once the SWF is loaded into mc_Empty2, I want to remove the faded background movieclip from mc_Empty1.  When I load the SWF from the main timeline, the onLoad() function works and removes the faded background from mc_Empty1.  However, when I load the SWF from mc_target, the SWF loads, but the onLoad() function does not.  Here's my AS2 code:

       

      //Loading SWF from main timeline

      mc_Empty1.attachMovie("mcFadedBg", "mc_FadedBg", 1);

       

      mc_Empty2.loadMovie("My.swf");
      mc_Empty2.onLoad = function():Void
      {
          trace("loaded"); //This works
          removeMovieClip(mc_Empty1.mc_FadedBg); //This works
      }

       

      //Loading SWF from mc_target

      _parent.mc_Empty1.attachMovie("mcFadedBg", "mc_FadedBg", 1); //This works

       

      _parent.mc_Empty2.loadMovie("My.swf"); //This works
      _parent.mc_Empty2.onLoad = function():Void //This does not work
      {
           trace("loaded"); //This does not work
           removeMovieClip(_parent.mc_Empty1.mc_FadedBg); //This does not work
      }

       

      I know I'm targeting properly because the SWF loads as it should, but the onLoad() function does not.  Any thoughts?  I'm using Flash CS4 and publishing for Flash Player 9.

        • 1. Re: onLoad working at _root level but not at mc_target level, why?
          kglad Adobe Community Professional & MVP

          none of your code is probably working the way you think it should work.

           

          1.  the onLoad() method is called when a movieclip is instantiated (ie, created) as long as the code executes BEFORE the movieclip is instantiated.  it has nothing to do with loading an external file (like My.swf).

           

          2.  mc_Empty2.onLoad will be call if mc_Empty2 appears on-stage no latter than the frame where your code executes.

           

          3.  code in a nested movieclip executes AFTER code attached to the parent frame.

          1 person found this helpful
          • 2. Re: onLoad working at _root level but not at mc_target level, why?
            atrzebunia Level 1

            Both, mc_Empty1 and mc_Empty2 are instances of mc_Empty already on the stage.  I'm not placing them on the stage using AS.  I just have them in layers; mc_Empty2 is above mc_Empty1 so that the faded background covers the SWF while it's loading.

             

            I see that I may be using onLoad() incorrectly, or may be thinking the onLoad() = once the SWF is fully loaded.  What function can I use to remove the faded background once the SWF is loaded into mc_Empty2?  I found loadClip() and onLoadComplete() but neither of these work.  Do you have any suggestions?

             

            Thanks.

            • 3. Re: onLoad working at _root level but not at mc_target level, why?
              kglad Adobe Community Professional & MVP

              :

               


              Both, mc_Empty1 and mc_Empty2 are instances of mc_Empty already on the stage.  I'm not placing them on the stage using AS.  I just have them in layers; mc_Empty2 is above mc_Empty1 so that the faded background covers the SWF while it's loading.

               

              so?

               

               

              I see that I may be using onLoad() incorrectly, or may be thinking the onLoad() = once the SWF is fully loaded.  What function can I use to remove the faded background once the SWF is loaded into mc_Empty2?  I found loadClip() and onLoadComplete() but neither of these work.  Do you have any suggestions?

               

              it's easiest to use the moviecliploader class.  it has an onLoadInit() method for its listener that works the way you're thinking those onLoad() methods should work.