Flash and SVG provide flexible and seamless communication with a database. The following information especially concerns Flash, which includes extremely powerful dedicated objects for remote data management. In all cases, a script page written in a language the server understands (ASP, PHP, JSP, etc.) is called by giving it parameters. Example of a page called: data.php?dept=12&var1=pop2099&var2=poptot99 This page contains typical instructions for connecting to the database and builds a SQL query using the parameters it receives. Example in PHP: $connection = mysql_connect(SERVER,NAME,PWD) or die("Database connection failed."); $data =mysql_select_db(BASE) ; $sql="select code_com, $HTTP_GET_VARS["var1"], $HTTP_GET_VARS["var2"] from result_rp99 where dept='$HTTP_GET_VARS["dept"]' "; $rs =mysql_query($sql) ; Once the query has been run, the result must be formatted and sent back to the Flash player (to the map). There are two possibilities: the result is transferred as a text file: it is in url-encoded (d1=12&d2=45&d3=67...) or xml format. Ideally, it must be compressed automatically using ZLIB and PHP functions ob_start("ob_gzhandler") and ob_end_flush(). If the browser supports decompression, the file can be compressed by the server before it is sent to the client workstation. the result is transferred as a SWF file, i.e. in binary code. Ideally it is compressed using ZLIB: it is by far the most compact format today. Before compressing the file, swf format writing functions must be used (custom functions based on SWF format specifications or Ming PHP library functions).
Flash manages the reception of data in text format through the loadVars() or loadXml() functions, and in SWF format through the loadMovie() function. Data is loaded in an independent object. Even better, load progress is monitored in real time by the getBytesLoaded() function. This information helps the user wait and enables the program to wait until loading has been completed before moving on to the next step. This prevents Adobe's SVG player from displaying error messages, as it does if javascript functions are called even though all the objects have not been loaded. 
|