7 Replies Latest reply on Oct 15, 2009 7:47 PM by kglad

    attaching movieclips inside other framed mcs?

    shintashi Level 1

      This is a program I wrote to attach a movie clip to a target:

       

       

      function avi(target, clip, hval, num, coordinatex, coordinatey){
          var hval:MovieClip = target.attachMovie(clip,clip+num , num+5);
      hval._x = coordinatex; hval._y = coordinatey;}

       

      example:

      avi(man.manR, "manRblack", k2, 2, 0, 0);

       


      -----

       

      it works on the surface, such as

       

      example:

      avi(man, "manRblack", k2, 2, 0, 0);

       

      but fails when the target has a parent. I.e.

       

      example:

      avi(man.manR, "manRblack", k2, 2, 0, 0);

       

      How do I target the "child" of a movieclip in order to attach a file to it?

        • 1. Re: attaching movieclips inside other framed mcs?
          kglad Adobe Community Professional & MVP

          as long as man.manR exists, that should work.

          • 2. Re: attaching movieclips inside other framed mcs?
            shintashi Level 1

            Edit:

             

            I thought there was something fundanmentally wrong with what I was trying to do so I made a simple program to test it out.

            >>

            function avi(target, clip, hval, num, coordinatex, coordinatey){
                var hval:MovieClip = target.attachMovie(clip,clip+num , num+5);
            hval._x = coordinatex; hval._y = coordinatey;}

             


            bar.onRelease = function(){
                avi(bar.box, "block", k2, 2, 0, 0);}
               
               
                goto2.onRelease = function(){bar.gotoAndStop(2);}
                    goto1.onRelease = function(){bar.gotoAndStop(1);}

             

            <<

             

             

            there are 5 objects in this program (all various boxes of different sizes - nothing complex).

             

            1. bar - the main movie clip. Click "bar" to attach "block" to "bar.box"

            2. block - the movie clip to be loaded from library

            3. box - a child of "bar". box only exists on frame 2 of "bar"

            4. goto2 - a button that tells bar to go to frame 2, where "box" is located

            5. goto1 - a button that tells bar to go back to frame 1, where no "box" appears

             

            What Happened?

            When bar was on frame 2, where "box" was visible, attaching block works without errors. However, when bar is on frame 1, "block" does not attach to anything - even if you then go to frame 2 to see if it attached in the memory - the program only works on "active" frames. Worse still, even though the block attaches in frame 2 (if you are in frame 2), when you go from frame 2 into frame 1, and then back again, Block is no longer attached - it is forgotten.

            • 3. Re: attaching movieclips inside other framed mcs?
              kglad Adobe Community Professional & MVP

              again, as long as man.manR exists, that should work.

               

              or, if bar.box exists, that should work.

               

              when you're on frame 1, bar.box does not exist.  it doesn't matter whether the playhead has spent eternity/2 in frame 2 where bar.box DOES exist, when the playhead goes returns to bar's frame 1, bar.box does NOT exist.

              • 4. Re: attaching movieclips inside other framed mcs?
                shintashi Level 1

                the problem with the program - and you can test it yourself -

                is that when you return to frame 2, the attached file is no longer present.

                 

                It can be re attached by the same command as it was the first time, and this can be done an infinite number of times.

                 

                My goal is for the attached block to stay attached so that I do not have to re-attach it the next time I go to frame 2.

                 

                My goal is the ability to go from

                bar.box to bar.box.block

                 

                and not have to keep telling bar.box to add .block every time I get to frame 2. I want it to remember whenever it goes to frame 2,

                there should be a .block there.

                 

                If this program can work, then I can switch out concealed portions of a movieclip. The uses are almost endless, everything from paperdoll avatars to customizing interior leather for an automobile program. In terms of analogy: I don't want to make something like "add shiny new spark plugs" option then close the hood (frame 1) only to have the shiny new spark plugs vanish when I open the hood again (frame 2).

                • 5. Re: attaching movieclips inside other framed mcs?
                  kglad Adobe Community Professional & MVP

                  that's expected if the movieclip to which the object was attached no longer exists.  in your case, the parent instances in the two frames are not the same.

                  • 6. Re: attaching movieclips inside other framed mcs?
                    shintashi Level 1

                    knowing that switching frames can cause the parent to disappear, and knowing that any child attached to the parent also permanently disappears even if the parent is braught back,

                     

                    is there a workaround that allows the child of the parent to be swapped (a changeling?) permanently?

                     

                    The only other way I know to do this is to have one master movie clip with transparent parents that all appear on the first frame, and are always playing, but because only one parent (and it's child) is visible (alpha 100) the movieclip has the appearance of changing directions with arrow keys.

                     

                    it just seemed more manageable with frames.

                    • 7. Re: attaching movieclips inside other framed mcs?
                      kglad Adobe Community Professional & MVP

                      you can't reparent objects in as2.

                       

                      nevertheless, i think you have some basic misunderstanding of flash.  if a movieclip is created with actionscript, it will remain until and unless it's removed with actionscript or one of its parents are removed.

                       

                      a movieclip created in the authoring environment exists until and unless another keyframe is encountered where that movieclip does not exist.

                       

                      so, when you attach your movieclip using attachMovie(), it will remain unless you use actionscript to remove it (which you're not) or, one of its parents are removed (which you are doing) by going to a keyframe where the immediate ancestor of the attached movieclip does not exist.  and, in fact, the grandparent of your attached movieclip also must not exist in that other frame (even though you probably think it does exist because it probably looks the same and is named the same).

                       

                      anyway, the workaround is no workaround.  just don't remove any parent of your attached movie and you're attached movieclip will continue to exist.

                       

                      if you want your attached movieclip to be visible in some frames and not visible in others, then use its _visible property or sometimes its _alpha property or even its _x and/or _y properties.

                      1 person found this helpful