7 Replies Latest reply on May 11, 2007 8:50 AM by cre8ive1974

    How to Swap a MC for another MC

    cre8ive1974 Level 1
      Is it possible to swap a MC with a MC in my library?

      It seems logical that you could, but I'm not sure how.

      For example

      I have a red ball on the stage that is a movie clip with an instance name of of "redBall" (clever huh?)

      In my library I have a movie clip of a greenball.

      On the stage I have a green button and a red button, you click the green button and I want the ball to turn green , click the red button and you guessed it, it turns red!

      How i've been doing this is in the past is on the stage I would put both movieclips on frame 1name the instances to each red ball = redBall, green ball = greenBall

      On the timeline on frame 1 I would put
      redBall._visible = true;
      greenBall._visible = false;

      on the green button I would put
      on (press) {
      redBall._visible = false;
      greenBall._visible = true;

      on the red button I would put
      on (press) {
      greenBall._visible = false;
      redBall._visible = true;

      while this works, I can't help but feel there is a better way of doing things. After all what if I had 30 _mc on the stage, that's a lot of true/false statements.

      Any help and examples would be appreciated/
        • 1. Re: How to Swap a MC for another MC
          Armen Abrahamyan Level 1
          u can have container movieclip in stage and just unload/load it with attachMovie method(ur balls must be in library with linkage names)
          from the other hand why don't have just one ball and change color via setRGB method ?
          • 2. Re: How to Swap a MC for another MC
            cre8ive1974 Level 1
            The ball_mc is just an example, the actual images are much more complex, in fact they are photographs. so the changing RGB is not an option.

            • 3. Re: How to Swap a MC for another MC
              Rothrock Level 5
              Okay so to keep the analogy alive. You have a photo of a green ball and a photo of a red ball. Make each one a movieclip.

              Then make a new clip called ball, in that put one of the red and one of the green. Give them instance names of red and green respectively. Make sure they line up.

              Now when ever you want the red one to show:


              And vice versa. You could also fade them in and out, etc. You could also use swapDepths to bring one in front of the other.


              Another way to maybe approach this as you extend the number of possibilities is that you keep an array of all the choices:


              Then for your buttons – and for heaven's sake stop using on(clipEvent) notation – you could have this.


              function hideClips(){
              Ball[myArray[ i ]]._visible=false;

              That will hide them all and then make the one you want visible again.
              • 4. Re: How to Swap a MC for another MC
                Armen Abrahamyan Level 1
                If actual images are photographs than use unloadMovie/loadMovie .
                So you you will have one container: holder_mc
                and after will unload/load there your images.
                • 5. How to Swap a MC for another MC
                  cre8ive1974 Level 1
                  Thanks Rothrock.
                  That works great!

                  Also you mentioned that it's possible to fade the colors in and out. Is it possible to do this so that the green ball fades to red when selecting the red button while the ball is green, or would it have to fade the green out and then fade the red in?

                  Thanks again!
                  • 6. Re: How to Swap a MC for another MC
                    Rothrock Level 5
                    Yes, in this case by fade, I meant fade the transparency of one or both of the clips. If you were only fading one clip you would want it to be on top. It would also require some different kind of function than the simple "hide them all then bring back the one you want." I'm not sure exactly what form it would take, maybe something the following pseudo function – by pseudo meaning I"m too lazy to work it all out, but the general steps might be:

                    function fadeTwo(currentClip,newClip){
                    //hide all
                    //put current clip on top of stack and make it visible
                    //put new clip second in stack and make it visible, but with alpha 0
                    //tween the current clip's alpha to 0
                    //tween the new clips alpha to 100
                    //make the current clip (which is now the old clip) not visible when it gets to 0 alpha

                    You would need some variable outside of your buttons keeping track of which clip was the current one showing. Then each button would be:


                    Or some such.
                    • 7. Re: How to Swap a MC for another MC
                      cre8ive1974 Level 1
                      Thanks for the help Rothrock!