9 Replies Latest reply on Jun 28, 2006 6:58 PM by twistedpancreas

    Random, scaling animation, per viewing

    twistedpancreas Level 1
      Hi there,

      I've got a animation to do for a science experiment, simulating a student adding some solution (iodine) into a flask (with disolved vitamin c). At some point the vitamin c solution needs to change colour, and the iodine solution stops being added to the vitamin c. See diagram

      Now there will be 400 students viewing this animation online from different machines, so I'd like the vitamin c solution to stop and change colour at different times (thus having the iodine solution stopping at different measurements in volume in the tube).

      So I was wondering if each time this flash animation was accessed it would stop at a randomly chosen frame and then swamp one symbol for another (ie i would have the iodine solution scaling down the tube, and if flash could stop at a certain frame then the soultion would stop, then at that same spot if it could swap the gray vitamin c symbol for a red vitamin c symbol)

      Hopefully that makes sense and look forward to you're help.
        • 1. Re: Random, scaling animation, per viewing
          kglad Adobe Community Professional & MVP
          each time your flash plays, it can generate however many random numbers you need to start, stop or otherwise make your display of this experiment be (roughly) unique for each visitor.
          • 2. Re: Random, scaling animation, per viewing
            twistedpancreas Level 1
            when you say "however many random numbers", do you mean random numbers within a range (ie the animation will only stop somewhere between frames 20 to 80, if the animation was 100 frames long in total)?

            so how would one go about setting this up?
            • 3. Re: Random, scaling animation, per viewing
              See4th Level 1
              So you would have:
              - a flask of disolved vitamin c solution
              - simulated pour of iodine solution from a tube
              - the flask filling
              - the tube emptying
              - a change of color in the flask

              I think I'm good so far, but the whole random frame on each viewing is fuzzy. So here it goes...

              If you create the animation one long _root timeline you could have code in frame 1 that picks a random frame and plays from there:

              var numberOfFrames:Number = 45; // the length of your animation in frames
              var rnd:Number = Math.floor(Math.random() * numberOfFrames); // picks a random number between 0 and 45

              Now for the changing of color. Make the liquid in the flask tween from a gray tint to a red tint - instead of using two clips you only need tween the one.

              Let me know if you need any additional help.


              • 4. Re: Random, scaling animation, per viewing
                See4th Level 1
                If you need to use a range between 20 and 80, modify the code as such:

                var startRange:Number = 20;
                var endRange:Number = 80;
                var rnd:Number = Math.floor(Math.random() * (endRange - startRange + 1)) + startRange; // picks a random number between 20 and 80
                • 5. Re: Random, scaling animation, per viewing
                  twistedpancreas Level 1
                  you're pretty close See4th except the animation needs to play from the begining and stop at a random frame (before frame 45 from your example)

                  it's only then at that stopped frame, that the flask changes colour (basically the iodine won't change the colour of the vitamin c until it's molecules out number the vitamin c's, gee i didn't expect to be teaching a science lesson here :) especially since im no way at all a scientist)
                  • 6. Random, scaling animation, per viewing
                    See4th Level 1
                    I built an fla for you at:

                    Let me know how it works out for you.

                    • 7. Random, scaling animation, per viewing
                      twistedpancreas Level 1
                      You're the man Jeff!!!

                      I've looked at what you've done and it seems to make sense.

                      Is there anyway I could also have a random number appear under the flask that displays what the mass of the flask liquid is. It would need to be a random mass number within a range, say inbetween 10-50gms (to 2 decimal points)

                      Because in the end the students will need to have the mass divided by the volume of liquid used to get the vitamin c change colour

                      and will the student be able to type in the answer to this equation with the answer being in a certain range?

                      thx once again
                      • 8. Re: Random, scaling animation, per viewing
                        See4th Level 1
                        I'll help you with the mechanics, but it's important that wrap your head around this.

                        We are currently generating a random number between 0 and 70. To make things easier on you we'll change our random number process slightly so that you don't have to work with 0 if it ever did hit. (see code below)

                        Now you will create number called amtDispensed and derive a formula that will always generate a number between 10 and 50 based on a random number of 1 to 70.

                        Add a dynamic text field to the bottom of the stage and give it an instance name of 'amt_txt'.
                        Then in your checkFrame function, add your formula that generates amtDispensed (your 10 to 50 number).
                        Then add a line that says amt_txt.text = amtDispensed;

                        Let's get that much going. Post your code. When we tackle this, we'll move on to rounding the number to 2 decimals.

                        • 9. Random, scaling animation, per viewing
                          twistedpancreas Level 1
                          Sorry I'm wondering why the random number range of 10-50 needs to be based off the 1-70?

                          Basically the student will be given a mass of the vitamin c on screen (in our random range of 10-50) and write that down on a notepad, then they'll start the animation and find the difference in volume lost from the tube, ie take the reading before adding the iodine, then a reading after, at the end of the animation and then comparing the difference. So the mass of the vitamin c doesnt have any relationship with volume lost from the tube. I hope that makes sense.

                          I've found some code that will generate a random number, but not to a certain decimal point, see below:

                          function shuffle(){

                          return Math.floor(Math.random() * 2);


                          // create a master array

                          var allNumbers=[];

                          //populate it with the full set of numbers you want to use

                          for(var i=10;i<=20;i++){



                          //shuffle it


                          // create an array of results


                          // grab the number from the shuffled array

                          //and add it to the results array

                          for(var r=0;r<1;r++){



                          //show results



                          is this ok or is there something better?