Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

php + Mysql + Flash (ActionScript) tutorial

Codes here !

Moderators: macek, egami, gesf

php + Mysql + Flash (ActionScript) tutorial

Postby Joan Garnet » Sun Dec 22, 2002 10:57 am

Well,
I just want to share knowledge with people ;)
A script using FlashMX to create a simple php + Mysql weblog.

The database --> ( we call it: weblog )
id
names
coments

----------------------------------------------------------
The php script --> page.php
Code: Select all
<?php
//we'll keep it updated all the time, so we prevent from cache
header("Expires: ".gmdate("D, d M Y H:i:s")."GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
//Mysql conection data
$server = "localhost" ;
$login = "Joan_Garnet" ;
$pass = "mi_password";
$table = "weblog";
$bbdd = "my_database";
//conection itself
$db=mysql_connect($server,$login,$pass);     
mysql_select_db($bbdd,$db);
//select what we want to output
$sql="select * from ".$table." order by id desc";
$result = mysql_query($sql,$db);
$i=0;
//Flash reads php data using echo, and variables are passed through URL using the normal way --> file.php?bla=blah&bla2=blah2....
while ($row = mysql_fetch_array ($result)) {
   echo "my_coments".$i."=".$coments[$i++]=$row["coments"]."\n\n&";
   echo "my_names".$i."=\n".$names[$i]=$row["names"]."\n&";
}
?>

-----------------------------------------------------------
Now let's have a look at the page that embeds the flash file --> weblog.php

Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>.:weblog:.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="550" height="400">
<!-- let's prevent the cache again -->
  <?php $mi_var = gmdate("D d M Y H i s") ?>
  <param name="movie" value="php.swf?<?php echo $mi_var ?>" >
  <param name="quality" value="high">
  <embed src="php.swf?<?php echo $mi_var ?>" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"></embed></object>
</body>
</html>

------------------------------------------------------------
Finally, the ActionScipting --> php.swf

Code: Select all
//////////////////////////////////////////////
////////create theTextfield////////////////
////////////////////////////////////////////
createTextField("texto", 1, 10, 50, 400, 200);
//create HTML style so it looks better :)
_estilo = "<font face='Verdana' size='16' color='#990000'>";
estilo_ = "</font>";
// some Textfield properties:
with (texto) {
   border = true;
   borderColor = 0x990000;
   background = true;
   backgroundColor = 0xECECEC;
   multiline = true;
   html = true;
   wordWrap = true;
   htmlText = _estilo+"Loading Mysql data........ "+estilo_;
}
//this line let users use weird characters like ^´`ñ etc...
System.useCodePage = true;
//////////////////////////////////////////////
//////////let's load Mysql data/////////////
/////////////////////////////////////////////
charge = new LoadVars();
charge.load("page.php");
//success is a boolean variable that Flash passes by default when using the LoadVars object
charge.onLoad = function(success) {
   _root.texto.htmlText = "";
   if (success) {
      //Scan variables from php and save them in a string
      for (i in this) {
         html_temp += this[i];
      }
      //when the string is fully loaded, we assign the style we previously created and output the result in the textfield
                               _root.texto.htmlText = _estilo+html_temp+estilo_;
   } else {
      _root.texto.text = "Error, unable to process Mysql data...";
   }
};
//this is an undocumented FlashMX function that prevents the "for in" from showing methods and properties of an object  that we don't want to be shown.
ASSetPropFlags(charge, ["onLoad"], 1);
//////////////////////////////////////////////
//////////Let's draw the interface/////////
//////////////////////////////////////////////
//We'll use the FlashMX draw API for the script to be cool :)
//this is slider for the button
createEmptyMovieClip("fondo_butt", 2);
with (fondo_butt) {
   beginFill(0xECECEC, 50);
   lineStyle(1, 0x990000, 50);
   moveTo(430, 45);
   lineTo(440, 45);
   lineTo(440, 255);
   lineTo(430, 255);
   lineTo(430, 45);
   endFill();
}
//this is the button itself
createEmptyMovieClip("butt", 3);
with (butt) {
   beginFill(0xECECEC, 100);
   lineStyle(1, 0x990000, 100);
   moveTo(420, 50);
   lineTo(450, 50);
   lineTo(450, 65);
   lineTo(420, 65);
   lineTo(420, 50);
   endFill();
}
//////////////////////////////////////////////
////Let's create the button events////////
//////////////////////////////////////////////
butt.onrollover = function() {
   this._alpha = 50;
};
butt.onrollout = function() {
   this._alpha = 100;
};
//this is the part where we create the scroll
butt.onpress = function() {
   startDrag(this, false, this._x, 0, this._x, (high=200-this._height));
   this.onmousemove = function() {
      pos_butt = int((texto.maxscroll/high)*this._y);
      texto.scroll = pos_butt;
      updateAfterEvent();
   };
};
butt.onrelease = function() {
   stopDrag();
};


Well, that's it!!!
Enjoy
;)
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby Oleg Butuzov » Sun Dec 22, 2002 1:46 pm

WoW ! :D

Joan maight be you have ICQ ? Knok into my ICQ. My UIN 318183 =). I have one proposition about you =)
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron