Flash
  Home arrow Flash arrow Page 5 - Building Data-Driven Flash Movies
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

Building Data-Driven Flash Movies
By: The Disenchanted Developer, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 71
    2002-07-23


    Table of Contents:
  • Building Data-Driven Flash Movies
  • Message In A Bottle
  • No Hands
  • No News Is Good News
  • Alien Invasion
  • What's On The Menu?
  • Splitting Up
  • Linkzone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building Data-Driven Flash Movies - Alien Invasion
    ( Page 5 of 8 )

    Let's assume that the news headlines to be displayed are stored in a database table which looks something like this:

    +---------------------+------------------------------------------------ | date | body +---------------------+------------------------------------------------| 2001-12-20 10:16:48 | An extra-terrestrial materialized outside the rabbit hole today. Calling itself ALICE, this ET claims to have come from a planet named ... | | 2001-12-20 10:20:58 | Executives at Robots'R'Us today announced the launch of their latest multi-function household assistant, IDA (I'll Do Anything), the most sophisticated ... | +---------------------+------------------------------------------------
    The script "ticker.php" needs to connect to this database and extract the five most recent records from it. This data can then be converted into form-encoded data and picked up by the Flash movie.

    Here's the code to accomplish this:

    <? // ticker.php // open connection to database $connection = mysql_connect("localhost", "root", "secret") or die ("Unable to connect!"); mysql_select_db("news") or die ("Unable to select database!"); // formulate and execute query $query = "SELECT body FROM stories ORDER BY date DESC LIMIT 0,5"; $result = mysql_query($query) or die("Error in query: " . mysql_error()); if (mysql_num_rows($result) > 0) { // iterate through rows while($row = mysql_fetch_object($result)) { // build headline string $str .= $row->body . " * "; } // print output as form-encoded data echo "content=" . urlencode($str); } // close connection mysql_close($connection); ?>
    Again, this is fairly simple. The script first connects to the database server, selects a database and executes an SQL query to select the five most recent stories from the system. A "while" loop is used to iterate over the returned resultset, with the content of each record appended to a single string, separated by an asterisk.

    Once the entire string has been constructed, it is encoded via PHP's urlencode() function and sent to the standard output, where it can be picked up by the Flash movie.

    If PHP isn't your cup of tea, you can also do this in Perl - here's the code you'll need:

    #!/usr/bin/perl # load module use DBI(); # connect my $dbh = DBI->connect("DBI:mysql:database=news;host=localhost", "root", "secret", {'RaiseError' => 1}); # execute query my $sth = $dbh->prepare("SELECT body FROM stories ORDER BY date DESC LIMIT 0,5"); $sth->execute(); print "content="; # iterate through resultset while(my $ref = $sth->fetchrow_hashref()) { print "$ref->{'body'} * "; } # clean up $dbh->disconnect();
    Here's what the output of the script might look like:

    content=Executives+at+Robots%27R%27Us+today+announced+the+launch+of+thei r+la test+multi-function+household+assistant%2C+IDA+%28I%27ll+Do+Anything%29% test+multi-function+household+2C+t he+most+sophisticated+...+%2A+An+extra-terrestrial+materialized+outside+ he+most+sophisticated+the+ rabbit+hole+today.+Calling+itself+ALICE%2C+this+ET+claims+to+have+come+f rabbit+hole+rom+ a+planet+named+...+%2A+
    With the server-side component in place, and the Flash movie all prepped and ready to go, all that's left is to test the movie again. This time, the text box should be dynamically populated with the results of the SQL queries in the script above, and should display this data as a scrolling news ticker along the bottom of the movie.



    As the database is updated with new stories, the Flash file will automatically read and display them via the server-side script "ticker.php". Pretty cool, huh?

     
     
    >>> More Flash Articles          >>> More By The Disenchanted Developer, (c) Melonfire
     

       

    FLASH ARTICLES

    - An Overview of Flash and ActionScript
    - Building Web Forms In Flash
    - Building Data-Driven Flash Movies
    - Flash 101 (part 6): The Final Countdown
    - Flash 101 (part 5): Spiralling Out Of Control
    - Flash 101 (Part 4): Don't Touch Me!
    - Flash 101 (part 3): Bouncing Around





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT