7 Replies Latest reply on May 17, 2006 7:32 PM by Craig Grummitt

    swap cast members

    cre8ive1974 Level 1
      Is it possible to change out a movie clip with another movie clip. All within one frame?

      If anyone knows Lingo similar to this.

      on mousedown me
      sprite(39).member = "mysprite"
      end mousedown me

      Any ideas?
        • 1. Re: swap cast members
          Jim_Esteban Level 1
          I think yes if both movieClips are already loaded. Are we talking about images?
          • 2. Re: swap cast members
            Craig Grummitt Level 3
            here you go - here's an equivalent of that lingo(where whatever is the instance name of a movie clip on stage, and swapper is the linkage identifier of a symbol in the library...
            whatever.onPress = function() {
            swapWith(this._name, "swapper");
            function swapWith(mc, libLinkage) {
            var mcX = this[mc]._x;
            var mcY = this[mc]._y;
            this.attachMovie(libLinkage, mc, 2);
            this[mc]._x = mcX;
            this[mc]._y = mcY;

            as you can see it isn't the easiest approach in flash which is why other techniques are usually used instead. For example, if you're just trying to set up a mousedown state, it's easiest to just implement a button with a down state.. Alternatively you could set up a movie clip with several frames and go to a specific frame on mousedown (rather than swapping out a library item)
            • 3. Re: swap cast members
              cre8ive1974 Level 1
              Thanks for the response!

              I only have a moderate understanding on ActionScript. I will need to research your code to understand what all that means.

              I will give a detailed explanation of what I am trying to do.

              I am making a color selector for an item that my company sells.
              There are 10 colors available for this particular item.
              Initially when the user goes to the color selector area on the web all they will see is an oultine of the item, no color is respresented on the item.
              The user can then click whatever color they would like...lets say red...and the item will change to red. Then if they want to change the color again to lets say blue..then the color of the item will change to blue..etc...
              I can set up the movieclip (named myItem) by putting the outline item on frame 1, the red item on frame 2 the blue item on frame 3 etc...
              then attach the following code to the buttons used to change the colors..

              on the red button use

              on(release) {

              on the blue button use

              on(release) {


              However all this accomplishes is a quick jump to the color with no sort of transition. I would like to have an effect so the color fades in. However if the user is on the red color of the item and wants to go to the blue color of the item the transition would need to begin with the red color and finish with the blue color. But if they were on another color like yellow and wanted to go to blue then it would need to begin with the yellow color and end with the blue color.

              There would be many many different color changes from color1 to color2 depending on what color they are on to begin with and what color they wanted to see. So making a movieclip for each color change blue to red, red to yellow, yellow to blue , etc..would be quite labor intensive, not to mention setting up the movieclip would be a nightmare.

              The item I am speaking of is a 3d rendering .jpeg

              So this is what I was thinking..again I am not sure if this is possible so bear with me if this makes no sense

              I was thinking of making 10 different movieclips that began with an alpha of 0 and ended with an alpha of 100 for each color and name them redfadeIn, bluefadeIn, yellowfadeIn etc.... This would make the fade in transition. Then make another 10 movieclips that were just a still image of the item in it's particular color. redStill, blueStill, yellowStill, etc...

              I would also have a movieclip that is the still image of the item with no color. I would name this movieclip noColor_item. I would also create an empty moviclip that is of the same size and location as the fade in transitions from above (redfadeIn etc...) I would name this movieclip myEmpty_Clip.

              Then within the myItem movieclip, have on frame 1, layer 1 the movieclip noColor_item (this will show the default image when that part of the Flash file plays). Then on layer 1, frame 2 have the movieclip noColor_item again, however on layer 2, frame 2 put myEmpty_Clip. Then when the user clicks the blue color selector button the myEmpty_Clip will put the bluefadeIn movie clip in its place. So we will have the illusion that the blue color is fading in.

              Then when the user clicks the red button, the blueStill movie clip will be put into frame 2 layer 1 in place of the movieclip noColor_item (becasue they are currently viewing the item in blue) and the redfadeIn moviclip will be put in frame 2, layer 2 in place of the bluefadeIn movieclip becasue now the image is fading to red.


              Like I said before I am sort of new with Actionscript and am limited in my knowledge of it. So if this scenario is "crazy talk" then please steer me in a better direction.

              I keep using this site as an example. it uses a wipe transition, but it still offers the same idea that I am looking for.


              Thanks in advance
              • 4. swap cast members
                Craig Grummitt Level 3
                you're on a good track, but yeah there are a couple of areas i suspect you may need some confusions cleared up.
                are you suggesting doing everything with action-script? you can't specify frames to put movieclips into - only movieclips(the _root is a movieclip). layers are different to levels. levels are like layers but are referred to only by action-script.
                here's my suggestion loosely based on yours.
                the myItem movie clip:
                layer 1 - noColor_item
                layer 2 - stills_MovieClip - this has a blank first frame(with a stop action), and then 10 frames of stills.
                layer 3 - fadeIn_MovieClip - this has a blank first frame(with a stop action), and then 10 frames of fadeIns. on the final frame of the fadeIn, will go to the equivalent still frame in stills_MovieClip, and then goes to the blank first frame. (For reusability, all of this could be contained in a function on the root that is just called on the final frame of the fadeIn movies)
                • 5. Re: swap cast members
                  cre8ive1974 Level 1
                  Thanks for the response. I am still a little confused with what you are suggesting. Not sure how to make that work. If I have three layers within the movieclip won't I see what is on each layer? So in essence I will have overlaping of my images?

                  I am probably way confused.

                  • 6. Re: swap cast members
                    Level 7
                    Here's a solution I use quite often to load external JPGs (uploaded to
                    the same directory as my HTML page containing the SWF). It uses the
                    MovieClipLoader Class, the Tween Class and also some code I got from
                    this forum -- from kglad -- to achieve relatively seamless transitions
                    from one JPG to another. It looks complicated, but probably only
                    because I did a lot of commenting on the code.


                    /* Create a "holder" movie clip -- perhaps just a white rectangle
                    of your desired size converted to a movie clip symbol. Drag an instance
                    of the holder symbol to the stage at your desired position
                    and give it instance name "imageHolder1_mc". Make a new layer and drag
                    another instance of the holder clip to the exact same coordinates on
                    stage (i.e. on "top" of the other holder)and give it instance name
                    "imageHolder2_mc". These clips will holder your old and new images of
                    different colors, per the users selection. Then create a new layer for
                    scripting and copy and paste the code below into the actions panel*/

                    // import the tween and easing classes
                    import mx.transitions.Tween;
                    import mx.transitions.easing.Regular;
                    // create a listener object for the movie clip loader
                    var mclListener bject = new Object();
                    // set up what will happen once your new clip/jpg is loaded
                    mclListener.onLoadInit = function(target_mc) {
                    trace("load init");
                    // bring the new clip above the old clip
                    // fade in the new clip over 1.5 seconds
                    var loaderTween:Tween = new Tween(target_mc, "_alpha",
                    Regular.easeInOut, 0, 100, 1.5, true);
                    // create the movie clip loader object
                    var loader_mcl:MovieClipLoader = new MovieClipLoader();
                    // attach the listener to the loader
                    // assign the two "holder" clips
                    var top = imageHolder2_mc;
                    var bottom = imageHolder1_mc;
                    //top and bottom swapping function
                    function loadSWF(photo) {
                    //swap names and depths
                    var temp = bottom;
                    bottom = top;
                    top = temp;
                    // load something into "top"
                    loader_mcl.loadClip(photo, top);
                    // make the call to load your first jpg

                    /* Then just set up your buttons -- the color boxes that your user will
                    click on to choose the color. Give them instance names on stage, like
                    "chooseRed_btn" and "chooseBlue_btn". Then attach an action to each
                    button by adding something like the code below to your actions layer
                    script */

                    // red button chooser code
                    chooseRed_btn.onRelease = function() {
                    // blue button chooser code
                    chooseBlue_btn.onRelease = function() {


                    Hope this helps!

                    cre8ive1974 wrote:
                    > Is it possible to change out a movie clip with another movie clip. All within
                    > one frame?
                    > If anyone knows Lingo similar to this.
                    > on mousedown me
                    > sprite(39).member = "mysprite"
                    > end mousedown me
                    > Any ideas?
                    > Thanks!
                    > D
                    • 7. Re: swap cast members
                      Craig Grummitt Level 3
                      if you follow my suggestion the first frame of the movieclips on layers 2 and 3 will be blank with a stop action, so you won't see them until the appropriate time.