4 Replies Latest reply on Jun 25, 2008 8:08 AM by kglad

    attach to loaded clip

      gooday
      i find that it is unable to attachMovie to the clip which is loaded by MovieClipLoader.loadClip()
      the code below
      -----------------------------------------
      //there is a library mc with linkage name "myObj"
      var ml:MovieClipLoader=new MovieClipLoader();
      var listener:Object=new Object();

      listener.onLoadInit=function(tar){
      var my_clip=tar.attachMovie("myObj", "mcMyObj", tar.getNextHighestDepth());
      trace(my_clip); //this returns undefined
      /*
      but changging to
      var my_clip=_root.attachMovie("myObj", "mcMyObj", tar.getNextHighestDepth());
      trace(my_clip); //this returns a correct reference~

      */
      }
      ml.addListener(listener);

      this.createEmptyMovieClip("mcContainer", this.getNextHighestDepth());
      ml.loadClip("somwhere", mcContainer);
      -----------------------------------------

      would anyone kindly solve my problem??
      thankyou
        • 1. Re: attach to loaded clip
          kglad Adobe Community Professional & MVP
          you can't do that. create a child of your load target and load into that and attach to the parent.
          • 2. attach to loaded clip
            clbeech Level 3
            I'm just wondering why you might want to do this as you could call to - tar.mcMyObj - since the variable will only be local to the method anyway. however you may have more success if you use:

            tar.attachMovie( ... );
            var my_clip = tar.mcMyObj;

            but I'm still thinking that this is a 'timing' (order of events) issue - as the onLoadInit fires when the first frame is ready to render - the obj attached may not be instantiated until the next frame plays - and therefore the obj attached doesn't yet 'exist' at the time the trace is being made - however with the call on the root, the timeline is already established so the object get instantiated immediately - but I'm guessing a bit here. if you place the trace within a onEnterFrame loop i think you'll find that on the second iteration the var returns the reference.

            edit: sorry kg - twas thinking about it - i see (above)
            • 3. Re: attach to loaded clip
              Level 1
              thankyou all

              clbeech, if my code stores at frame2? i dont know, ain't try it :p
              attaching this way is avoid making the MC tree too complex

              var my_clip=tar.attachMovie
              since Movieclip.attachMovie() returns a reference of attached mc
              referencing this way can avoid using tar["blar"+i]

              kglad:
              thanks for repkly, but im wondering, a loaded clip is a movieclip isn't it?
              a movieclip can contains child isn't it?
              when MovieClipLoader.onLoadInit() fired, isn't it able to access the clip?
              • 4. Re: attach to loaded clip
                kglad Adobe Community Professional & MVP
                you can't attach a movieclip to a loaded clip. flash won't allow it. why it isn't allowed, i do not know.

                read the work-around in my above message.