5 Replies Latest reply on Oct 26, 2006 11:25 PM by Newsgroup_User

    Bubbles

    sd120132
      Hello everyone,

      I'm building my own little aquarium and found a couple tuts on bubbles
      Flashkit Tutorial Here
      FlashDevils Tutorial Here

      I've asked around at these sites and other forums and haven't gotten any response so I'm hoping someone has a solution to my problem. Both of these tutorials feature bubbles coming from the bottom of the screen floating to the top which is perfect for one of the two effects I was looking for (simple background ambience). My question is can I combine the same MC effect with another animation on the screen, say a treasure chest that opens every 5 seconds, spits out bubbles for 3 seconds and then closes, turning off the bubbles (basically a timed burst of bubbles in a specific x,y position)?

      I've tried dropping the script into it's own MC (MC inside an MC) and placing 2 instances on the root timeline but that results in an error because the script has to be on the root and not within the MC. If I create two different MCs, each with different identifiers then on the root timeline, create two separate layers each with the identical code with the only difference being that the script calls each individual MC by it's specific identifier, it will only play one of the two MCs, but not both.

      To anyone that can help me, I'd appreciate it immensely. If there is simpler code to achieve this effect I'd love to hear it! Thanks in advance.

      -sd12013
        • 1. Re: Bubbles
          Level 7
          Hi!

          I used the setBubbles code on the second link. I made a copy of this
          function so that I have two. (This is because I made some modifications that
          might help you when you make the chest bubble. So you use the setBubbles for
          the background and setBubbles2 for the forground. I am including my whole
          code below (which I just placed in the root and had an MC in library linked
          with the name "blase"). In my example I fire off the "chest bubbles" right
          away, but you can call this function from some other place trigged by some
          other action.


          function setBubbles(obj, depth, xPos, yPos, maxNum, randHeight, randWidth,
          Height, Width) {
          this.createEmptyMovieClip(obj, depth);
          this[obj]._x = xPos;
          this[obj]._y = yPos;
          for (i = 1; i <= maxNum; i++) {
          this[obj].attachMovie("blase", "blup" + i,depth + i);
          this[obj]["blup" + i].tempo = random(7) + 5;
          this[obj]["blup" + i].randVal = random(4);
          this[obj]["blup" + i].direction = -1;
          this[obj]["blup" + i].ZS = random(50) + 10;
          this[obj]["blup" + i]._xscale = this[obj]["blup" + i].ZS;
          this[obj]["blup" + i]._yscale = this[obj]["blup" + i].ZS;
          this[obj]["blup" + i]._y = random(randHeight);
          this[obj]["blup" + i]._x = random(randWidth);
          this[obj]["blup" + i].onEnterFrame = function() {
          this._y -= this.tempo;
          this._x -= this.randVal;
          this.randVal += this.direction;
          if (this._y <= 0) {
          this._y = Height;
          this.randVal = random(4);
          this.tempo = random(7) + 5;
          this.ZS = random(50) + 10;
          }
          if (this._x <= 0) {
          this._x = Width - this._width;
          }
          if (this._x >= Width) {
          this._x = 0 + this._width;
          }
          if (this.randVal < -3) {
          this.direction = +1;
          }
          if (this.randVal > 3) {
          this.direction = -1;
          }
          };
          }
          }

          function setBubbles2(obj, depth, xPos, yPos, maxNum, randHeight, randWidth,
          Height, Width, startY, startX) {
          this.createEmptyMovieClip(obj, depth);
          this[obj]._x = xPos;
          this[obj]._y = yPos;
          for (i = 1; i <= maxNum; i++) {
          this[obj].attachMovie("blase", "blup" + i,depth + i);
          this[obj]["blup" + i].tempo = random(7) + 5;
          this[obj]["blup" + i].randVal = random(4);
          this[obj]["blup" + i].direction = -1;
          this[obj]["blup" + i].ZS = random(50) + 10;
          this[obj]["blup" + i]._xscale = this[obj]["blup" + i].ZS;
          this[obj]["blup" + i]._yscale = this[obj]["blup" + i].ZS;
          this[obj]["blup" + i]._y = random(randHeight)+startY;
          this[obj]["blup" + i]._x = random(randWidth)+startX;
          this[obj]["blup" + i].onEnterFrame = function() {
          this._y -= this.tempo;
          this._x -= this.randVal;
          this.randVal += this.direction;
          if (this._y < 0) {
          removeMovieClip(this);
          }
          if (this._x <= 0) {
          this._x = startX+Width - this._width;
          }
          if (this._x >= Width+startX) {
          this._x = 0 + this._width;
          }
          if (this.randVal < -3) {
          this.direction = +1;
          }
          if (this.randVal > 3) {
          this.direction = -1;
          }
          };
          }
          }
          setBubbles("room", 1, 0, 0, 30, 400, 550, 400, 550);
          // background bubble

          setBubbles2("room2", 2, 0, 0, 30, 50, 50, 400, 150, 400, 200); //
          chest bubble



          "sd120132" <webforumsuser@macromedia.com> wrote in message
          news:ehn820$m22$1@forums.macromedia.com...
          > Hello everyone,
          >
          > I'm building my own little aquarium and found a couple tuts on bubbles
          > http://board.flashkit.com/board/showthread.php?threadid=589417
          > http://www.flashdevils.com/showthread.php?threadid=18395/Bubbles%20(MX).html
          >
          > I've asked around at these sites and other forums and haven't gotten any
          > response so I'm hoping someone has a solution to my problem. Both of these
          > tutorials feature bubbles coming from the bottom of the screen floating to
          > the
          > top which is perfect for one of the two effects I was looking for (simple
          > background ambience). My question is can I combine the same MC effect with
          > another animation on the screen, say a treasure chest that opens every 5
          > seconds, spits out bubbles for 3 seconds and then closes, turning off the
          > bubbles (basically a timed burst of bubbles in a specific x,y position)?
          >
          > I've tried dropping the script into it's own MC (MC inside an MC) and
          > placing
          > 2 instances on the root timeline but that results in an error because the
          > script has to be on the root and not within the MC. If I create two
          > different
          > MCs, each with different identifiers then on the root timeline, create two
          > separate layers each with the identical code with the only difference
          > being
          > that the script calls each individual MC by it's specific identifier, it
          > will
          > only play one of the two MCs, but not both.
          >
          > To anyone that can help me, I'd appreciate it immensely. If there is
          > simpler
          > code to achieve this effect I'd love to hear it! Thanks in advance.
          >
          > -sd12013
          >


          • 2. Re: Bubbles
            sd120132 Level 1
            Thanks Jensen. Thanks for your quick response!

            I hate to bug but... is it possible to use this same type of trasure chest bubble ani within an MC that is moving around the aquarium, like on a little diver guy to simulate breathing bubbles? Or does the code always have to reside on the root?

            Thanks again.

            -sd12013
            • 3. Re: Bubbles
              Level 7
              Hi again!

              It is possible to do so with the code above. I made a square with dimension
              23x23 and turned it into an MC. Then inside it I added the following code:

              dir = -1;
              step = 10;
              counter = 5;
              onEnterFrame = function() {
              if (this._x < 10) {
              dir = 1;
              } else if (this._x > 500) {
              dir = -1;
              }
              this._x += dir*step*Math.random(5)*2;

              if ((this._x % 10) < 1) {
              _parent.setBubbles2("room"+counter, counter, 0, 0, 10, 30, 30, 400, 150,
              350, this._x+40*dir);
              counter++;
              }
              }

              "sd120132" <webforumsuser@macromedia.com> wrote in message
              news:eho0qu$m4f$1@forums.macromedia.com...
              > Thanks Jensen. Thanks for your quick response!
              >
              > I hate to bug but... is it possible to use this same type of trasure chest
              > bubble ani within an MC that is moving around the aquarium, like on a
              > little
              > diver guy to simulate breathing bubbles? Or does the code always have to
              > reside
              > on the root?
              >
              > Thanks again.
              >
              > -sd12013
              >


              • 4. Re: Bubbles
                sd120132 Level 1
                Jensen, thanks again! I really do appreciate your taking time to help me out. I have one last question though.

                It seems with that last bit of code we're on the right track, but the bubbles always seem to originate from the bottom of the movie rather than from the actual diver or the chest.

                As opposed to setting the xPos and yPos up front, can you tell it to call or reference the current location of the MC it's attached to and originate from those x/y coords at a certain time interval?

                Sorry to be so needy. Again, gracious thanks.

                -sd12013
                • 5. Re: Bubbles
                  Level 7
                  Hi again!

                  In the code I gave last time, you cand try to modify it to:
                  _parent.setBubbles2("room"+counter, counter, 0, 0, 10, 30, 30, 400, 150,
                  this._y, this._x+35*dir);

                  Note that I use "this._y" and "this._x" in there. You might have to adjust
                  the position a bit with some +/- value as I have done for the x value. The
                  "dir" that I multiply with is just a direction factor, so that I get the
                  bubbles on the left or right of the "box" depending on which direction it is
                  going.

                  Anyway, don't be afraid to experiment. You might run into some other
                  freature you have not thought about before ;-)

                  /Jensen/

                  "sd120132" <webforumsuser@macromedia.com> wrote in message
                  news:ehr9on$q20$1@forums.macromedia.com...
                  > Jensen, thanks again! I really do appreciate your taking time to help me
                  > out. I
                  > have one last question though.
                  >
                  > It seems with that last bit of code we're on the right track, but the
                  > bubbles
                  > always seem to originate from the bottom of the movie rather than from the
                  > actual diver or the chest.
                  >
                  > As opposed to setting the xPos and yPos up front, can you tell it to call
                  > or
                  > reference the current location of the MC it's attached to and originate
                  > from
                  > those x/y coords at a certain time interval?
                  >
                  > Sorry to be so needy. Again, gracious thanks.
                  >
                  > -sd12013
                  >