4 Replies Latest reply on Apr 23, 2006 12:16 PM by oon

    Fade In in actionscript

    oon
      Hi! Well... I have a little problem. i´m sorry for my bad english, i will try to explain the better as possible.
      Well...I´m working on a simple photo gallery, I have thumbnails on my main stage that works as buttons, like every photo gallery. I want to do the following: when press, flash creates a new Mc and loads the jpg image externally, and a textfield that mention that the archive is loading. Ok..this gallery it´s quite simple with only few images so i didn´t use Xml or other language to load files... all it´s embed in flash, statically.
      Well the problems are:
      - First of all I want to load jpg´s with a fade effect and It´s not working at all!.
      - I want to show a text in a textfield when image it´s loading, but i want to it disappear when image has ended loading.

      I show you the script:

      At the first frame i declare a function called fade and another called imageLoaded

      fade = function(){
      _root.image._alpha += (100-caption._alpha)/3;
      }
      imageLoaded = function(){
      _root.image.loadMovie();
      return ("ok");
      }


      And for last the script into the thumbnail (they are Mc´s)

      on(press){
      _root.createEmptyMovieClip("image",1);
      _root.image.loadMovie("1.jpg");
      _root.statustext.text="Please Wait . Image is loading";
      _root.image._x=119;
      _root.image._y=49;
      _root.image.fade();
      if(loadedImage == "ok") {
      _root.statustext.text=""; // nothing shows at the textfield
      }
      else {
      _root.statustext.text="There was a problem trying to load images";
      }
      }

      I will be very appreciated to those who can give me a help on this.
      Thank you!.
        • 1. Re: Fade In in actionscript
          Level 7

          "oon" <webforumsuser@macromedia.com> wrote in message news:e2e0p6$m0f$1@forums.macromedia.com...
          > on(press){
          > _root.createEmptyMovieClip("image",1);
          > _root.image.loadMovie("1.jpg");
          > _root.statustext.text="Please Wait . Image is loading";
          > _root.image._x=119;
          > _root.image._y=49;
          > _root.image.fade();


          Once you start loading into a movieclip, don't change x and y positions or do fades on it until the loading is finished.
          You can get around that restriction by using a double clip. The holder clip is used for positioning and alpha effects and the other
          clip loads the image.

          fade = function(){
          // the code used for caption._alpha was not provided so I can't check this
          // the formula looks odd though
          _root.mc1._alpha += (100-caption._alpha)/3;
          }

          imageLoaded = function(){

          // this makes no sense. What are you trying to do here?
          _root.image.loadMovie();
          return ("ok");
          }


          _root.createEmptyMovieClip("mc1",1);
          _root.mc1.createEmptyMovieClip("image",2);
          _root.mc1.image.loadMovie("1.jpg");
          _root.statustext.text="Please Wait . Image is loading";
          _root.mc1._x=119;
          _root.mc1._y=49;

          // you shouldn't start fading until the clip loads. Use a preloader.
          _root.fade();

          tralfaz


          • 2. Re: Fade In in actionscript
            oon Level 1
            Thank you! well...with imageLoaded function i was trying to get an ok variable when clip finished loading the image file, and then into the button i put if(loadedImage == "ok") {
            _root.statustext.text=""; // nothing shows at the textfield
            }
            else {
            _root.statustext.text="There was a problem trying to load images";
            }

            I was trying to set "statustext" to blank when movie ends loading.

            I delete x and y position on button actions and fade action too, so the only script I left there is

            on(press){
            _root.createEmptyMovieClip("image",1);
            _root..image.loadMovie("1.jpg");
            _root..statustext.text="Please wait";
            }

            I do not understand how double clip works so I tried putting the rest of the code at my first frame....but didn´t work =(

            First frame actions:
            image.onEnterFrame=function() {
            image._x=119;
            image._y=49;
            image._alpha += (100-image._alpha)/3;
            statustext.text="";
            }

            About script
            image._alpha += (100-image._alpha)/speed;
            It´s work ok in all my movies...

            Thanks if you can help again.
            regards.
            oon
            • 3. Re: Fade In in actionscript
              Level 7

              "oon" <webforumsuser@macromedia.com> wrote in message news:e2e7ao$t7j$1@forums.macromedia.com...
              > Thank you! well...with imageLoaded function i was trying to get an ok variable
              > when clip finished loading the image file, and then into the button i put
              > if(loadedImage == "ok") {
              <...>


              Well, I would start telling you all the things wrong with your code but it seems like that you are having problems with the code
              concepts in too many areas. Maybe you need a better starting point? If you make small changes to a working code and then test it
              you can learn what everything does.

              I made a little demo for you with loading of external images, fading in using a timer, thumbnails, preloader, ..etc Maybe you use
              it or adapt some of it. It is written in Flash MX (version 6). I don't use any components or built-in stuff.

              http://www.kompanionkare.net/flash/image/thumbnail1.html
              good luck,
              tralfaz


              • 4. Re: Fade In in actionscript
                oon Level 1
                Ey man, thanks a lot for your good will!! I´m very appreaciated, thank you