7 Replies Latest reply on Jul 26, 2006 5:45 AM by kypsul

    Targeting movie clips

    kypsul
      Hello everyone,

      I've worked on some code with a little help from some people here and I've gotten everything to work. The problem I am having right now is getting my cross fading images to sit inside separate movie clips that are on my home .swf. The code I have so far is as follows:

      var showTime:Number = 5000 // milliseconds the picture shows at 100% alpha.
      mc_Mon1 = createEmptyMovieClip("img1_mc", 0);
      loadMovie("images/home/image01.jpg", img1_mc); // load picture from the file directory that your .swf is in.

      mc_Mon1 = createEmptyMovieClip("img2_mc", getNextHighestDepth());
      loadMovie("images/home/image02.jpg", img2_mc);// load picture from the file directory that your .swf is in.

      img2_mc._alpha = 0; // hide 2nd picture

      var duration:Number = 30; // milliseconds per alpha change (framerate).
      var count:Number = 0;
      var alphaPhase:Number = 1;
      var alphaCount:Number = 0;

      function picSwap():Void {
      count++;
      if(count >= (showTime/duration)) {
      alphaCount += alphaPhase;
      img1_mc._alpha = 100-alphaCount;
      img2_mc._alpha = alphaCount;
      trace("img1 alpha: " + img1_mc._alpha);
      trace("img2 alpha: " + img2_mc._alpha);
      if(alphaCount >= 100 || alphaCount <= 0) {
      count = 0;
      alphaPhase *= -1;
      }
      }
      }
      var intervalId:Number = setInterval(picSwap, duration);
      // End of script.

      I am trying to make img1_mc and img2_mc sit inside mc_Mon1. So I am thinking that I would need mc_Mon1 to "createEmptyMovieClip" named "img1_mc and img2_mc. I thought thats what I did with the code but so far my cross fading images just sit up on the top left of the screen. Does anyone have any idea how to set the target movie clip to load the other movie clips?

      Thanks,

      Kyle
        • 1. Re: Targeting movie clips
          Level 7
          hi,
          you should make few changes in your code for it to work, starting with this:
          instead of - "mc_Mon1 = createEmptyMovieClip("img1_mc", 0);" and the
          following line, try - mc_Mon1.createEmptyMovieClip("img1_mc",
          mc_Mon1.getNextHighestDepth());
          mc_Mon1.img1_mc.loadMovie("images/home/image01.jpg");

          and then -
          mc_Mon1.createEmptyMovieClip("img2_mc", mc_Mon1.getNextHighestDepth());
          mc_Mon1.img2_mc.loadMovie("images/home/image02.jpg");

          mc_Mon1.img2_mc._alpha = 0;

          and then in picSwap function, it should be -
          mc_Mon1.img1_mc._alpha = 100-alphaCount;
          mc_Mon1.img2_mc._alpha = alphaCount;

          that should do it i think.
          just so you'd learn, in your original code, 'mc_Mon1' actually is variable
          reffering to 'img1_mc' (which, if i'm not mistaken, is created in _level0),
          but then 2 lines later you overwrite the refference to 'img1_mc' with a
          refference to 'img2_mc' (which is also created in _level0).
          one more thing which i didn't check - when you declare you 'intervalId',
          don't u need to use 'showTime' instead of 'duration'?

          good luck,
          eRez

          "kypsul" <webforumsuser@macromedia.com> wrote in message
          news:ea4dij$2d6$1@forums.macromedia.com...
          > Hello everyone,
          >
          > I've worked on some code with a little help from some people here and I've
          > gotten everything to work. The problem I am having right now is getting my
          > cross fading images to sit inside separate movie clips that are on my home
          > .swf. The code I have so far is as follows:
          >
          > var showTime:Number = 5000 // milliseconds the picture shows at 100%
          > alpha.
          > mc_Mon1 = createEmptyMovieClip("img1_mc", 0);
          > loadMovie("images/home/image01.jpg", img1_mc); // load picture from the
          > file
          > directory that your .swf is in.
          >
          > mc_Mon1 = createEmptyMovieClip("img2_mc", getNextHighestDepth());
          > loadMovie("images/home/image02.jpg", img2_mc);// load picture from the
          > file
          > directory that your .swf is in.
          >
          > img2_mc._alpha = 0; // hide 2nd picture
          >
          > var duration:Number = 30; // milliseconds per alpha change (framerate).
          > var count:Number = 0;
          > var alphaPhase:Number = 1;
          > var alphaCount:Number = 0;
          >
          > function picSwap():Void {
          > count++;
          > if(count >= (showTime/duration)) {
          > alphaCount += alphaPhase;
          > img1_mc._alpha = 100-alphaCount;
          > img2_mc._alpha = alphaCount;
          > trace("img1 alpha: " + img1_mc._alpha);
          > trace("img2 alpha: " + img2_mc._alpha);
          > if(alphaCount >= 100 || alphaCount <= 0) {
          > count = 0;
          > alphaPhase *= -1;
          > }
          > }
          > }
          > var intervalId:Number = setInterval(picSwap, duration);
          > // End of script.
          >
          > I am trying to make img1_mc and img2_mc sit inside mc_Mon1. So I am
          > thinking
          > that I would need mc_Mon1 to "createEmptyMovieClip" named "img1_mc and
          > img2_mc.
          > I thought thats what I did with the code but so far my cross fading images
          > just
          > sit up on the top left of the screen. Does anyone have any idea how to set
          > the
          > target movie clip to load the other movie clips?
          >
          > Thanks,
          >
          > Kyle
          >
          >


          • 2. Re: Targeting movie clips
            kypsul Level 1
            awesome! It worked great. I have one last question. How do I manage to get ore than two images per movie clip. RIght now I have two images that load and corss fade. I would like that have maybe five that load and cross fade.

            Thanks again for your help.

            Kyle
            • 3. Re: Targeting movie clips
              Level 7
              Kyle,
              glad that phase one went successfully...
              about adding more images - a simple option would be to simply create 3 more
              empty MC's and load the other images into them, but then when u crossfade u
              have 2 keep account of which 2 images u're crossfading every time.
              a more neat way, which will easily allow u 2 add more images in the future,
              is stick to your 2 MC's you already have, put all the images u want to load
              in an array, and then at the end of every crossfade load the next image in
              the array into the MC with 0 alpha (u'll need to have some counter to tell
              you which image is next). in case your application works offline there
              should be no problem with that, in case it works online you'll have to add
              some mechanism that checks if the image is ready before it begins fading
              in - let me know if that's the case and u have problem with this addition.

              good luck,
              eRez

              "kypsul" <webforumsuser@macromedia.com> wrote in message
              news:ea54h3$g0$1@forums.macromedia.com...
              > awesome! It worked great. I have one last question. How do I manage to get
              > ore
              > than two images per movie clip. RIght now I have two images that load and
              > corss
              > fade. I would like that have maybe five that load and cross fade.
              >
              > Thanks again for your help.
              >
              > Kyle
              >
              >


              • 4. Re: Targeting movie clips
                kypsul Level 1
                Well this is going to be part of a website so it will be online. The array thing is the part that I will have a hard time with. I've never really built one but I figured with what I am trying to do I would probably have to build it. I know nothing about them. If you could give me a couple pointers that would be great.

                Thanks,

                Kyle
                • 5. Targeting movie clips
                  kypsul Level 1
                  I've built an array. I've called the array into the movie clip. Now I don't see any images, but the fade seems to be working when I debug. Any suggestions?

                  var dyArray:Array = new Array();
                  dyArr[0] = "images/home/image01.jpg";
                  dyArr[1] = "images/home/image02.jpg";
                  dyArr[2] = "images/home/image03.jpg";
                  dyArr[3] = "images/home/image04.jpg";
                  dyArr[4] = "images/home/image05.jpg";


                  // Script to load two pictures and cycle them with a fading effect.
                  // Note: This looks a lot better with 30 frames/second.
                  var showTime:Number = 500 // milliseconds the picture shows at 100% alpha.
                  mc_Mon1.createEmptyMovieClip("img1_mc", mc_Mon1.getNextHighestDepth());
                  mc_Mon1.img1_mc = dyArray;// load picture from the file directory that your .swf is in.

                  mc_Mon1.createEmptyMovieClip("img2_mc", mc_Mon1.getNextHighestDepth());
                  mc_Mon1.img2_mc = dyArray;

                  mc_Mon1.img2_mc._alpha = 0; // hide 2nd picture*/

                  var duration:Number = 10; // milliseconds per alpha change (framerate).
                  var count:Number = 0;
                  var alphaPhase:Number = 1;
                  var alphaCount:Number = 0;

                  function picSwap():Void {
                  count++;
                  if(count >= (showTime/duration)) {
                  alphaCount += alphaPhase;
                  mc_Mon1.img1_mc._alpha = 100-alphaCount;
                  mc_Mon1.img2_mc._alpha = alphaCount;
                  trace("img1 alpha: " + mc_Mon1.img1_mc._alpha);
                  trace("img2 alpha: " + mc_Mon1.img2_mc._alpha);
                  if(alphaCount >= 100 || alphaCount <= 0) {
                  count = 0;
                  alphaPhase *= -1;
                  }
                  }
                  }
                  var intervalId:Number = setInterval(picSwap, duration);
                  // End of script.

                  Thanks,

                  Kyle
                  • 6. Targeting movie clips
                    kypsul Level 1
                    Something weird happend...disregard this replay...sorry
                    • 7. Re: Targeting movie clips
                      kypsul Level 1
                      Does anyone know how to do this?