5 Replies Latest reply on Nov 30, 2010 2:26 PM by Rothrock

    Diminishing Oscillating Opacity

    RevolKeller

      Suppose I have an image in the background with a white box over the image. What I am trying to do is get the box to oscillate it's _alpha property while diminishing to zero. Producing a 'twinkling' effect. I have the actionscript on the box_mc in an onClipEvent (enterFrame) function. Really there will be a lot of these boxes so the oscillation would have to be random. Thanks! The code I have right now, which just lowers the opacity at a random rate - no oscillation is below: Thanks in advance!

       

      onClipEvent (load) {
          h = Math.random();
      }

       

      onClipEvent (enterFrame) {
          if (this._alpha>0) {
              this._alpha -= h;

          }
      }

        • 1. Re: Diminishing Oscillating Opacity
          RevolKeller Level 1

          Surely this isn't too hard....no replies, what determines what posts get answered or not.

          If it's not possible let me know. If it's too easy for you guys to even waste your time on, just give me a clue then.

          Or is it some sort of etiquette thing, that I am not aware of?

          • 2. Re: Diminishing Oscillating Opacity
            Ned Murphy Adobe Community Professional & MVP

            It's probably a mix of things... possibly an issue with a somewhat vague explanation of what you want.  But a more prominent aspect is that while it might not be too hard to do, it involves someone taking the time to do all the work for you, which isn't what folks generally do in these forums.  If there's a ready-made solution handy, then someone might offer it.  But in this case, it is probably a unique scenario requiring someone to first get the design requirements straightened out and then determine a solution, and then devise it.  It might not be hard, but that doesn't mean it happens with the snap of one's fingers.

             

            So it is best if you come with more of an attempt to solve it yourself, explaining what your code is supposed to be doiing and what it fails to do.  The less work you make for those you seek help from, the more likely they are to try.

             

            Beyond your intitial posting, when you come back behaving as though something is owed to you, and you pretty much demand folks respond... well that's just not in the book of winning friends and influencing people, and works against any form of etiquette.  And if you feel the need to lash out at me for explaining any of what I just did, please understand, I am not intending to offend you, just offering it for consideration.

            • 3. Re: Diminishing Oscillating Opacity
              RevolKeller Level 1

              hmmm....let's try this again.

               

              Part I:

              I have a box on the stage. I populate a grid of boxes on the stage via the code in frame 1 of main timeline:

               

              gridx=100;
              gridy=100;
              num=0;

               

              for (var i=0;i < 8;i++)
              {
                for (var j=0;j < 6;j++)
                {
                  box.duplicateMovieClip("box"+num,num);
                  mc=this["box"+num];
                  mc._x=gridx*i+50;
                  mc._y=gridy*j+50;
                  mc._alpha=Math.random()*100+80;
                  num++;
                }
              }

               

              Part II:

              Now that the boxes are 'gridded' out on the stage I want them to 'twinkle' off. I have each of them fading down randomly by placing code on the box' first frame with the code:

               

              onClipEvent (load) {
                  h = (Math.random()*10)-5;
              }

               

              onClipEvent (enterFrame) {
                  if (this._alpha>0) {
                      this._alpha -= h;
                  }
              }

               

              I am trying to get the box to decrease it's opacity but just not straight down. I want it to oscillate. It seems to me that using a Math.sin in the h variable assignment but I can't seem to get it to work. Think diminshing wave. The _alpha would go up and down but with a stronger down move than up. Two steps back one step forward kind of thing.

               

              Any ideas? Anyone?

              • 4. Re: Diminishing Oscillating Opacity
                RevolKeller Level 1

                So cs5 is able to make this happen through the motion editor, but I have to animate manually. The motion editor lets me draw a curve that will diminish opacity the way I want to called a damped wave. The problem is I have to do this to all boxes on the grid.

                 

                Would still be nice to know if there is a way to do this in actionscript though.

                • 5. Re: Diminishing Oscillating Opacity
                  Rothrock Level 5

                  It sounds like you need tweening and easing. You should check out TweenLite.

                   

                  http://www.greensock.com/tweenlite/