A Final Example


This section presents a final example. The following is a simple HTML site that contains images of three people:

 <html> <head> </head> <body text="#000000" bgcolor="#FFFFFF" link="#0000EF" vlink="#59188E"      alink="#FF0000"> <b><font size=+1>The final Flash example:</b> <center><p><b>Click your favourite persons</b> <p><br> <table BORDER COLS=3 WIDTH="90%" NOSAVE >     <tr>      <td><b>Ewald Geschwinde</b></td>      <td> <center><b>Etschi Bruckner</b></center></td>      <td><div align=right><b>Hans-Juergen Schoenig</b></div></td>     </tr>     <tr>         <td><a href="display.php?fname=Ewald&sname=Geschwinde">                 <img src="epi.jpg" height=130 width=84></a></td>      <td><center><a href="display.php?fname=Etschi&sname=Bruckner">              <img src="etschi.jpg" height=130 width=107></a></center></td>      <td><div align=right>              <a href="display.php?fname=Hans-Juergen&sname=Schoenig">              <img src="hans.jpg" height=130 width=121></div></td>     </tr> </table> </body> </html> 

If we display the HTML code with the help of Netscape 4.77, it looks like Figure 14.8.

Figure 14.8. Click to see your favourite person in action.

graphics/14fig08.gif

If a user clicks an image, display.php is called with the name of the person and the picture.

Every person has an entry in table cybertec ; we use this information to generate the movie:

 myflash=#  SELECT firstname, surname, pic FROM cybertec;  firstname     surname       pic --------------+------------+------------  Ewald         Geschwinde  epi.jpg  Hans-Juergen  Schnig     hans.jpg  Etschi        Bruckner    etschi.jpg (3 rows) 

The following is the source code of display.php:

 <?php      dl('php_ming.so');      # connecting to the database      $dbh=pg_connect("dbname=myflash user=hs");      if    (!$dbh)      {              echo ("ERROR: connecting failed");              exit;      }      # selecting data from the PostgreSQL      $sql="SELECT * FROM cybertec WHERE firstname='$fname'";      $result=pg_exec($dbh, $sql);      if    (!$result)      {              echo ("ERROR: cannot failed");              exit;      }      # creating the movie      $m = new SWFMovie();      $m->setDimension(640, 480);      $m->setRate(12);      # retrieving the data line by line      if (pg_numrows($result) < 1)      {              echo ('no results found');              exit;      }      else      {              $data=pg_fetch_object ($result, 0);              $b = new SWFBitmap(fopen($data->pic, "r"));              $width = $b->getWidth();              # first pic of Etschi ...              $i = $m->add($b);              $i->scaleTo(1.2, 1.2);              $i->skewXTo(-0.2);              $i->moveTo(320-$width, 100);              # second pic of Etschi ...              $i = $m->add($b);              $i->scaleTo(1.2, 1.2);              $i->skewXTo(0.2);              $i->moveTo(320, 100);              $i = $m->add($b);              $i->moveTo(320-$width/2, 100);              for($n=0; $n<23; $n+=0.1)              {                      $i->rotateTo($n*8);                      $i->multColor($n, $n, $n);                      $i->addColor(0, 0, 0, -$n);                      $m->nextFrame();              }              header('Content-type: application/x-shockwave-flash');              $m->output();      } ?> 

As in all the examples, we connect to the database first and query the table to compute the information that we need to generate the Flash movie. We do this with the help of a simple SELECT statement. In the example, we look for firstname . One record will be retrieved and we will use the content of this record for our Flash movie.

After creating an SWFMovie object, we set the size and define the speed of the movie. If the result of the query satisfies our demands, we continue generating the movie; otherwise , an error is displayed. Then we open the picture of the person that the user has clicked. The name of the picture is stored in $data->pic . In the next step, we compute the size of the image; we will need this information later in the script. $i=$m->add($b) adds the image to the movie.

Note

All transformations of the image are done after adding it to the scenery .


After adding the object to the scenery, we perform basic transformations, such as scaling the picture to the correct size or setting the initial position of the picture. The whole process is done twice, so the picture is displayed two times.

In the next step, we add a third picture to the scenery, perform some rotation, and change the color of the object every time the loop is processed .

Figure 14.9 shows a screenshot of the movie in action.

Figure 14.9. Animating the author's girlfriend.

graphics/14fig09.gif

If you want to find out more about the Ming interface, check out http://www. opaque .net/ming/.



PostgreSQL Developer's Handbook2001
PostgreSQL Developer's Handbook2001
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 125

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net