5 Replies Latest reply on Aug 21, 2006 1:42 PM by abeall

    Mutliple framed MovieClip and its Class

    Level 7
      I have a 4 framed MovieClip in my library named 'MC Swatch Set' with a
      defining class named SwatchSet. Each of the frames contains 2 - 4
      MovieClips with instance names
      swatch1
      swatch2
      swatch3
      swatch4

      For this post, please refer to
      http://www.seanberry.com/swatches.png

      On frame 1, swatch 1 and 3 are present.
      On frame 2, swatch 1, 2 and 3.
      On frame 3, swatch 1, 3 and 4.
      and on 4, swatch 1, 2, 3 and 4.

      In my class I have an _init() function that takes two args. The first is
      the label of the frame to jump to out of the 4. The second argument is an
      object that is used to specify the colors to use with setRGB on the various
      swatches. So, if the _init() function was called and the first argument was
      'P1S2' the MovieClip would go to frame 3 ( P1S2 == '1 Primary color, and 2
      secondary colors')

      Since there will only ever be one of these "MC Swatch Set" MovieClips, I
      only instantiate it once when I place it on the stage with an attachMovie().

      So here is the problem. When I call the _init() the first time, it works
      like a charm. It goes to the correct frame, and changes the colors of the
      swatches. But, when I call _init() again, with new parameters, I encounter
      a problem.

      The problem is best illustrated in the image referenced above. Basically,
      even though I know the MovieClip instance is changing frames (I know this
      because I put a trace on each frame which works and because the outlines of
      the swatches on the MovieClip are correct) the instance of the movieclip I
      have already used is visible.

      Is it because I can only use an instance name once? Since I have, for
      example, a movieclip with instance name swatch2 on frames 2 and 4, is it
      whichever one gets used first?

      Thanks.




        • 1. Re: Mutliple framed MovieClip and its Class
          abeall Level 3
          I would say there's a very good chance this is indeed because you are re-using instance names. Try giving every swatch a unique name, or seperate the frames on the timeline with blank keyframes.
          • 2. Re: Mutliple framed MovieClip and its Class
            Level 7

            "abeall" <webforumsuser@macromedia.com> wrote in message
            news:eccs5s$2aq$1@forums.macromedia.com...
            >I would say there's a very good chance this is indeed because you are
            >re-using instance names. Try giving every swatch a unique name, or seperate
            >the frames on the timeline with blank keyframes.

            AWESOME SOLUTION!!!

            It worked. But, now... why? If I have a MovieClip instance with name
            "swatch1" on frame 1 and then another instance of the same MovieClip with
            instance name "swatch1" on frame 2, I would think that as long as you as you
            were on the correct frame (1 or 2) then any reference would be to the
            MovieClip instance on that frame with the instance name specified.

            Thanks again.


            • 3. Re: Mutliple framed MovieClip and its Class
              abeall Level 3
              I don't exactly know, other than Flash thinks the same instance is on frame 1 and frame 2 if they have the same name, and that can easily confuse Flash if in actuality they are different.

              Try this. Create a MovieClip in the IDE called "myMovie_mc". Make the document 20 frames. On frame 10, put:
              myMovie_mc.swapDepths(1);
              myMovie_mc._x += 150;
              myMovie_mc._y += 150;
              myMovie_mc._alpha = 50;

              No stop() commands. Now play the movie. Congradulations, you have successfully confused the Flash Player! :-) Similar type of thing, I think.
              • 4. Re: Mutliple framed MovieClip and its Class
                Level 7

                "abeall" <webforumsuser@macromedia.com> wrote in message
                news:ecd12k$840$1@forums.macromedia.com...
                >I don't exactly know, other than Flash thinks the same instance is on frame
                >1
                > and frame 2 if they have the same name, and that can easily confuse Flash
                > if in
                > actuality they are different.
                >
                > Try this. Create a MovieClip in the IDE called "myMovie_mc". Make the
                > document
                > 20 frames. On frame 10, put:
                > myMovie_mc.swapDepths(1);
                > myMovie_mc._x += 150;
                > myMovie_mc._y += 150;
                > myMovie_mc._alpha = 50;
                >
                > No stop() commands. Now play the movie. Congradulations, you have
                > successfully
                > confused the Flash Player! :-) Similar type of thing, I think.
                >

                Yep, that demonstrates a similar problem. What I don't understand though,
                is why there is a copy of myMovie_mc in the new position, with the new alpha
                when the player loops back to frame 1. Just counter-intuitive it seems.

                Thanks again for the help. The empty keyframe in between frames containing
                like instance names did the trick and was a simple solution to implement.

                I had found other ways around this problem, like individual, unique instance
                names for each MovieClip but like your solution much better.



                • 5. Mutliple framed MovieClip and its Class
                  abeall Level 3
                  > What I don't understand though,
                  > is why there is a copy of myMovie_mc in the new position, with the new alpha
                  > when the player loops back to frame 1. Just counter-intuitive it seems.
                  Sorry, I didn't really finish my thought, there. The underlying problem, I think, is that when Flash reaches a keyframe, it will instantiate a new object if it thinks it doesn't already exist. For some reason, AS can seemingly easily confuse Flash as to what already exists and what does not. In the above example, it is swapDepths that confuses Flash. In your example, I think it's a similar issue. Something in the AS on the first frame, confuses Flash on the following frames, since the object is still. However, making sure all old objects are gone means that Flash is free to instantiate new ones without there being conflicts.

                  Alternatively, it's possible that the mere fact you are calling init() on the same object twice(on two different frames) creates a conflict. Either way, by ensuring they are two completely seperate fresh objects by seperating them, as opposed to just seperate frames, fixed it.