20 Replies Latest reply on Feb 16, 2010 8:50 AM by Limon26

    target movie clip fade within function

    Limon26 Level 1

      I'm working with this function that is loading in different .swf files based on buttons that are clicked:

       

      this.createEmptyMovieClip("targetMC",this.getNextHighestDepth());

       

      function loadF(y:Number, d:Number) {
      targetMC.loadMovie("floors_swf/"+y+"_"+d+".swf");
      }

       

       

      I want the targetMC to fade in and out, can I add that functionality into the function above

      or is that something that needs to be done in each .swf file that I'm loading in?

        • 1. Re: target movie clip fade within function
          kglad Adobe Community Professional & MVP

          if you want to do a cross-fade (ie, one fades-out while another fades-in), you'll need, at least, two target movieclips.  otherwise, you'll see the prior load suddenly disappear and then sometime later (after loading is complete) the next one starts to fades-in.  do you want the cross-fade?

          • 2. Re: target movie clip fade within function
            Limon26 Level 1

            I think I'd like to have it fade out totally, then have the next one fade in. The images are very close to one another with a few changes so I think it may look less like it's jumping if the 1st one fades out. 

             

            Is it harder to do it that way?

            • 3. Re: target movie clip fade within function
              Limon26 Level 1

              All of the code I've been looking at to do the fade starts with an array of all the content, in my case, .swf files.  I have about 100 that could possibly be loaded in depending on what buttons on clicked.

              Using this function below as a starting point, will I still have to create an array of 100 some .swf files or is there an easier way to do this?

               

              this.createEmptyMovieClip("targetMC",this.getNextHighestDepth());

              //////////function to load in .swf files/////////////////////

              function loadF(y:Number, d:Number) {

                   targetMC.loadMovie("floors_swf/"y"_"d".swf", 1);

              }

              • 4. Re: target movie clip fade within function
                Limon26 Level 1

                I've tried to integrate some examples into my function, am I on the right track?  I created the 2 empty movie clips:

                 

                this.createEmptyMovieClip("targetMC1",this.getNextHighestDepth());

                this.createEmptyMovieClip("targetMC2",this.getNextHighestDepth());

                targetMC2._alpha = 0;

                trace(targetMC2._alpha);

                trace(targetMC1._alpha);

                activeTarget = target1;

                //////////function to load in .swf files/////////////////////

                function loadF(y:Number, d:Number) {

                     targetMC1.loadMovie("floors_swf/"y"_"d".swf", 1);

                     if (activeTarget == target1) {

                          obj1 = target1;

                          obj2 = activeTarget = target2;

                     } else {

                          obj1 = target2;

                          obj2 = activeTarget = target1;

                     }

                      

                      

                }

                • 5. Re: target movie clip fade within function
                  kglad Adobe Community Professional & MVP

                  use:

                   

                  var fadeRate:Number = 3;

                  var mcl:MovieClipLoader=new MovieClipLoader();

                  var lo:Object={};

                  lo.onLoadInit=function(target:MovieClip){

                  clearInterval(fadeI);

                  currMC = target;

                  fadeI=setInterval(fadeF,target,otherTargetF(target));

                  }

                  mcl.addListener(lo);

                   

                  function fadeF(currMC:MovieClip,prevMC:MovieClip){

                  currMC._alpha += fadeRate;

                  prevMC._alpha -= fadeRate;

                  if(currMC._alpha>=100&prevMC._alpha<=0){

                  clearInterval(fadeI);

                  }

                  updateAfterEvent();

                  }

                   

                  this.createEmptyMovieClip("target1MC",this.getNextHighestDepth());

                  this.createEmptyMovieClip("target2MC",this.getNextHighestDepth());

                  var currMC:MovieClip = target2MC;

                   

                  function loadF(y:Number, d:Number) {
                  otherTargetF(currMC).loadMovie("floors_swf/"+y+"_"+d+".swf");
                  }

                   

                  function otherTargetF(mc:MovieClip):MovieClip{

                  if(mc._name=="target1MC"){

                  return target2MC;

                  } else {

                  return target1MC;

                  }

                  • 6. Re: target movie clip fade within function
                    Limon26 Level 1

                    This is the code that I currently have on one of my buttons:

                     

                     

                    mybtn.onRelease = function() {

                         _global.theFloor = 1;

                         loadF(theYear,1);

                         gotoAndStop(3);

                     

                    };

                     

                    The buttons don't seem to work now with the new code.  Does something need to be updated in the button code?

                    • 7. Re: target movie clip fade within function
                      kglad Adobe Community Professional & MVP

                      my error.  try:

                       

                      :

                       

                      var fadeRate:Number = 3;

                      var mcl:MovieClipLoader=new MovieClipLoader();

                      var lo:Object={};

                      lo.onLoadInit=function(target:MovieClip){

                      clearInterval(fadeI);

                      currMC = target;

                      fadeI=setInterval(fadeF,target,otherTargetF(target));

                      }

                      mcl.addListener(lo);

                       

                      function fadeF(currMC:MovieClip,prevMC:MovieClip){

                      currMC._alpha += fadeRate;

                      prevMC._alpha -= fadeRate;

                      if(currMC._alpha>=100&prevMC._alpha<=0){

                      clearInterval(fadeI);

                      }

                      updateAfterEvent();

                      }

                       

                      this.createEmptyMovieClip("target1MC",this.getNextHighestDepth());

                      this.createEmptyMovieClip("target2MC",this.getNextHighestDepth());

                      var currMC:MovieClip = target2MC;

                       

                      function loadF(y:Number, d:Number) {
                      mcl.loadClip("floors_swf/"+y+"_"+d+".swf",otherTargetF(currMC));

                      );
                      }

                       

                      function otherTargetF(mc:MovieClip):MovieClip{

                      if(mc._name=="target1MC"){

                      return target2MC;

                      } else {

                      return target1MC;

                      }

                      • 8. Re: target movie clip fade within function
                        Limon26 Level 1

                        ok, when i click one of my year buttons:

                         

                        y2008.onRelease = function() {
                            _global.theYear = 2008;
                            trace(_global.theYear);
                            trace(_global.theFloor);
                            loadF(2008,theFloor);
                        };

                         

                         

                        it does not load anything.  with the trace, it traces 2008 and 18 so it should load in that flash file but nothing loads?

                        • 9. Re: target movie clip fade within function
                          Limon26 Level 1

                          actually, i think i have the button aspect worked out, I'm tracing loadF in each button and it is loading in the

                          correct file name, but when I load in another .swf it just seems to load overtop of the existing file.

                           

                          Is there something I can trace for to see what is causing the overlap?

                          • 10. Re: target movie clip fade within function
                            kglad Adobe Community Professional & MVP

                            another error.  use:

                             

                            kglad wrote:

                             

                            my error.  try:

                             

                            :

                             

                            var fadeRate:Number = 3;

                            var mcl:MovieClipLoader=new MovieClipLoader();

                            var lo:Object={};

                            lo.onLoadInit=function(target:MovieClip){

                            clearInterval(fadeI);

                            currMC = target;

                            fadeI=setInterval(fadeF,target,otherTargetF(target));

                            }

                            mcl.addListener(lo);

                             

                            function fadeF(currMC:MovieClip,prevMC:MovieClip){

                            currMC._alpha += fadeRate;

                            prevMC._alpha -= fadeRate;

                            if(currMC._alpha>=100&prevMC._alpha<=0){

                            clearInterval(fadeI);

                            }

                            updateAfterEvent();

                            }

                             

                            this.createEmptyMovieClip("target1MC",this.getNextHighestDepth());

                            this.createEmptyMovieClip("target2MC",this.getNextHighestDepth());

                            var currMC:MovieClip = target2MC;

                             

                            function loadF(y:Number, d:Number) {

                            otherTargetF(currMC).swapDepths(Math.max(target1MC.getDepth(),target2MC.getDepth()));

                            mcl.loadClip("floors_swf/"+y+"_"+d+".swf",otherTargetF(currMC));

                            );
                            }

                             

                            function otherTargetF(mc:MovieClip):MovieClip{

                            if(mc._name=="target1MC"){

                            return target2MC;

                            } else {

                            return target1MC;

                            }

                            • 11. Re: target movie clip fade within function
                              Limon26 Level 1

                              Ok, I think there might be an issue with the fade.  When I click one of my buttons to first load in the first .swf file, the correct file loads in, but there is no fade.  I tried changing the fadeRate:Number from 3 to 30 or 1 to see if the fade was going to fast and I missed it, but it didn't do anything. 

                               

                              Also in the first button that I click, I added 2 traces in:

                               

                              trace(currMC._alpha);

                              trace(target1MC._alpha);

                               

                              They both traced as 100.  Does that help ?

                              • 12. Re: target movie clip fade within function
                                kglad Adobe Community Professional & MVP

                                if you want the first loaded file to fade-in, use:

                                 


                                 

                                 

                                :

                                 

                                var fadeRate:Number = 3;

                                var mcl:MovieClipLoader=new MovieClipLoader();

                                var lo:Object={};

                                lo.onLoadInit=function(target:MovieClip){

                                clearInterval(fadeI);

                                currMC = target;

                                fadeI=setInterval(fadeF,target,otherTargetF(target));

                                }

                                mcl.addListener(lo);

                                 

                                function fadeF(currMC:MovieClip,prevMC:MovieClip){

                                currMC._alpha += fadeRate;

                                prevMC._alpha -= fadeRate;

                                if(currMC._alpha>=100&&prevMC._alpha<=0){  //<-fix this line.  there was a typo in my previous code

                                clearInterval(fadeI);

                                }

                                updateAfterEvent();

                                }

                                 

                                this.createEmptyMovieClip("target1MC",this.getNextHighestDepth());

                                this.createEmptyMovieClip("target2MC",this.getNextHighestDepth());

                                var currMC:MovieClip = target2MC;

                                target1MC._alpha = 0;

                                 

                                function loadF(y:Number, d:Number) {

                                otherTargetF(currMC).swapDepths(Math.max(target1MC.getDepth(),target2MC.getDepth()));

                                mcl.loadClip("floors_swf/"+y+"_"+d+".swf",otherTargetF(currMC));

                                );
                                }

                                 

                                function otherTargetF(mc:MovieClip):MovieClip{

                                if(mc._name=="target1MC"){

                                return target2MC;

                                } else {

                                return target1MC;

                                }

                                 

                                • 13. Re: target movie clip fade within function
                                  Limon26 Level 1

                                  ok, with this new code, and the first button I press:

                                   

                                  rotation.floor19.onRelease = function() {
                                      _global.theFloor=19;
                                      loadF(theYear,19);
                                      gotoAndStop(8);
                                      trace(loadF);
                                      trace(currMC._alpha);
                                      trace(target1MC._alpha);
                                  };

                                   

                                   

                                  it traces murrMC at 100

                                  and target1MC at 0.

                                   

                                  no .swf file shows up though.  Is target1MC the MC that is supposed to be 100?

                                  • 14. Re: target movie clip fade within function
                                    kglad Adobe Community Professional & MVP

                                    another error:

                                     


                                     


                                     

                                     

                                    :

                                     

                                    var fadeRate:Number = 3;

                                    var mcl:MovieClipLoader=new MovieClipLoader();

                                    var lo:Object={};

                                    lo.onLoadInit=function(target:MovieClip){

                                    clearInterval(fadeI);

                                    currMC = target;

                                    fadeI=setInterval(fadeF,40,target,otherTargetF(target));

                                    }

                                    mcl.addListener(lo);

                                     

                                    function fadeF(currMC:MovieClip,prevMC:MovieClip){

                                    currMC._alpha += fadeRate;

                                    prevMC._alpha -= fadeRate;

                                    if(currMC._alpha>=100&&prevMC._alpha<=0){

                                     

                                    clearInterval(fadeI);

                                    }

                                    updateAfterEvent();

                                    }

                                     

                                    this.createEmptyMovieClip("target1MC",this.getNextHighestDepth());

                                    this.createEmptyMovieClip("target2MC",this.getNextHighestDepth());

                                    var currMC:MovieClip = target2MC;

                                    target1MC._alpha = 0;

                                     

                                    function loadF(y:Number, d:Number) {

                                    otherTargetF(currMC).swapDepths(Math.max(target1MC.getDepth(),target2MC.getDepth ()));

                                    mcl.loadClip("floors_swf/"+y+"_"+d+".swf",otherTargetF(currMC));

                                    );
                                    }

                                     

                                    function otherTargetF(mc:MovieClip):MovieClip{

                                    if(mc._name=="target1MC"){

                                    return target2MC;

                                    } else {

                                    return target1MC;

                                    }

                                     

                                    • 15. Re: target movie clip fade within function
                                      Limon26 Level 1

                                      The fade works now!  The only problem I see is that the file runs very very slow now.  I have all my files running locally so it's not a server issue.  I made an .exe file and tested it too, but it's just as slow.

                                      Is it possible to have a fade that doesn't take so long?

                                      • 16. Re: target movie clip fade within function
                                        Limon26 Level 1

                                        Do I have to unload or clear out all the .swf files after I'm done loading them in?  Maybe that's why it is running so slow ?

                                        • 17. Re: target movie clip fade within function
                                          kglad Adobe Community Professional & MVP

                                          you can change the fadeRate, you can change the setInterval() time and you can change the fps of your swf to control the fade characteristics.  to speed things, increase the fadeRate, decrease the setInterval() time (2nd parameter) and increase the fps of your swf.

                                           

                                          nothing needs to be removed.

                                           

                                          please mark this thread as answered, if you can.

                                          • 18. Re: target movie clip fade within function
                                            Limon26 Level 1

                                            Great, that really made a difference in speed.  Does it matter if the .swf files that you load in are a different fps than your container .swf file?   I have a main button that takes you back to the main interface, when I click the file that was previously loaded in needs to be unloaded.  Can I use an unloadMovie script to remove that file?

                                            • 19. Re: target movie clip fade within function
                                              kglad Adobe Community Professional & MVP

                                              the frame rate of all loaded swfs will default to the frame rate of the main (_level0) swf.  there's nothing you can do to change that.  but, it is possible to play any movieclip at any frame framerate (within certain limits) using actionscript.

                                               

                                              to unload something loaded using the moviecliploader class, you should use unloadClip:

                                               


                                              mcl.unloadClip(target1MC);

                                              mcl.unloadClip(target2MC);

                                              • 20. Re: target movie clip fade within function
                                                Limon26 Level 1

                                                When I load in a new .swf file into my main movie, it appears to load on top of the main movie.

                                                 

                                                This is the load function that we set up:

                                                 

                                                this.createEmptyMovieClip("target1MC",this.getNextHighestDepth());

                                                this.createEmptyMovieClip("target2MC",this.getNextHighestDepth());

                                                var currMC:MovieClip = target2MC;

                                                target1MC._alpha = 0;

                                                 

                                                function loadF(y:Number, d:Number) {
                                                otherTargetF(currMC).swapDepths(Math.max(target1MC.getDepth(), target2MC.getDepth()));

                                                mcl.loadClip("floors_swf/"+y+"_"+d+".swf",otherTargetF(currMC));

                                                }

                                                 

                                                 

                                                 

                                                Is there a way to get the .swf file that gets loaded in to load behind the graphics in my main movie?

                                                It appears to be loading into the target1MC, but I don't see where to set the level that it loads into?

                                                 

                                                Thanks