4 Replies Latest reply on Feb 5, 2007 3:37 PM by Daye1314

    Help Needed  for Monitoring animation

    Daye1314
      Hi, all.

      I got question on real time monitoring program here. I am wondering how can do that in flash.
      Basicly we have a senosr to keep track of the depth of water. The data of the water depth are stored in sql database.
      According to the data we stored, i want to show an animation which demonstrates how the water depth varies for some time period( change the color and depth of the water model inside flash ). Can anybody give me some advice on how to achieve this? I want to know how should i get the data from database into flash, Maybe write an asp.net web page to generate data in xml formate and let flash read it? still, how to achieve this), and how can i generate the animation within the program? Definitely, i can't draw it with the interface, cause i can get data only at run time.
      thanks for any clue and help.
        • 1. Re: Help Needed  for Monitoring animation
          Level 7
          >>Maybe write an asp.net web page to generate data in xml formate and let
          >>flash read it?

          That is one way. You could also have the asp page just return the data to
          flash directly, sidestepping xml. Have a look at the LoadVars class,
          specifically it's sendAndLoad method which has an example of sending data to
          a cold fusion script, but it's no different for ASP or PHP.

          Say you wanted to get the water levels for some date range. In Flash write a
          function like so:

          var allWater:Array = new Array();
          function getWaterLevels(fromDate:String, toDate:String){
          var recv = new LoadVars();
          var snd = new LoadVars();
          recv.onLoad = function(success) {
          if(success){
          allWater = [];
          var ind = 1;
          while(this["id" + ind]){
          var curWater = [];
          curWater.push(this["id" + ind]);
          curWater.push(this["date" + ind]);
          curWater.push(this["level" + ind]);
          allWater.push(curWater);
          ind++;
          }
          }
          }
          snd.start_date = fromDate;
          snd.end_date = toDate;
          snd.sendAndLoad(" http://domain.com/scripts/getwater.php", newsR);
          }

          I use PHP so you'll have to adapt, but you'd do something like so:

          <?PHP
          $connection = mysql_connect("localhost", "dbuser", "dbpassword");
          mysql_select_db("databaseName", $connection);

          $sql = "SELECT id,thedate,level FROM watertable WHERE thedate BETWEEN
          '$_POST[start_date]' AND '$_POST[end_date]'";

          $result = mysql_query($sql, $connection);

          $rString = "";
          $row = mysql_fetch_array($result);
          $ind = 1;
          while ($row){
          $rString .= "&id$ind=".$row["id"];
          $rString .= "&date$ind=".$row["thedate"];
          $rString .= "&level$ind=".$row["level"];

          $row = mysql_fetch_array($result);
          $ind++;
          }
          exit($rString);
          ?>

          Hopefully, that'll get you going. It's untested, but I modified some known
          working code to give you an example you could relate to.

          So, you have the data in Flash now, how to animate it... You can use Flash's
          drawing API to create vector shapes on the fly. You could simply move a
          shape up and down according to the data, etc...a few ways you could approach
          this.



          --
          Dave -
          Head Developer
          www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Help Needed  for Monitoring animation
            Level 7
            I did say it was code I modified... <g>

            This line in the example:
            snd.sendAndLoad(" http://domain.com/scripts/getwater.php", newsR);

            Should read: snd.sendAndLoad(" http://domain.com/scripts/getwater.php",
            recv);

            since you want to call the onLoad function within the recv LoadVars object.


            --
            Dave -
            Head Developer
            www.blurredistinction.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/


            • 3. Help Needed  for Monitoring animation
              Daye1314 Level 1
              Thanks for the answer.

              But can u give me an example of how can i generate the animations with script, and later change them at different frams?
              Cause the time range might vary, so the number of frames might vary. Also, actually the number of water containers might
              vary as well (more than one). So i think i might need to use script to generate the graphs.
              More over, even if i draw the vetor graph through the interface, it seems not to be an object at all (have no instance name.) Should i convert the graph into movie clips? if yes, then how can i change the size/color of the movie clips at different frames ? (should i set the time line for each of the clip? or the movie clip don't have to have its own time line, only change the movie clips color/size at the main time line?)
              Really appreciate your help. I cross posted just because i don't know where should i post them. Won't let it happen again.