Download presentation
Presentation is loading. Please wait.
Published byRolf Holmes Modified over 9 years ago
1
Using Flash with php Very quick introduction to Flash Homework: work on projects
3
Challenge want Flash for 'flashy' front end Need server to hold permanent (persistent) information –database! –Flash to/from php
4
Set up database (table) modification of createfavorites table Also need to put initialize –insert 4 records, with 0 for votescast Write stand-alone php scripts –display results –re-set votescast fields to zero
5
$fields = "can_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, candidate char(50) NOT NULL, votescast INT NOT NULL"; createtable($tname, $fields); $query = "INSERT INTO votes VALUES (0,'Bush',0)"; $result = mysql_db_query($DBname,$query,$link); $query = "INSERT INTO votes VALUES (0,'Kerry',0)"; $result = mysql_db_query($DBname,$query,$link); $query = "INSERT INTO votes VALUES (0,'Nadar',0)"; $result = mysql_db_query($DBname,$query,$link); $query = "INSERT INTO votes VALUES (0,'Other',0)"; $result = mysql_db_query($DBname,$query,$link); mysql_close($link);
6
Flash graphics, text fields, components on Stage –Dynamic text fields –Input text fields –radio buttons (grouped) –push button with event handler specified ActionScript –function to respond to push button –function invoked upon return from server script
7
Flash as front end LoadVars() sets up object to be used for variables to and from server script sendAndLoad is a method of a LoadVars object
8
Frame Action var connect = new LoadVars(); function gotoserver() { // This Tells the Flash movie What function to invoke when the Load Vars Is complete. connect.onLoad = getback; connect.data = president.getvalue(); connect.sendAndLoad("addtoresults2.php", connect, "POST"); }
9
Upon return from script function getback() { display.htmlText = connect.display; } where display is the text field. Limited number of HTML tags
10
Flash to php The variable (data) is passed to the script. Data is passed back by setting &display –considered a property of the connect object
11
<?php $data= $HTTP_POST_VARS['data']; $host="localhost"; $user="curley"; $password="12345"; $DBname="firstdb"; $link=mysql_connect($host,$user,$password); print "&display="; $query = "UPDATE votes SET votescast = votescast+1 WHERE candidate = '".$data. "'"; $result = mysql_db_query($DBname,$query,$link); $query = "SELECT * FROM votes"; $result = mysql_db_query($DBname,$query,$link); while ($row=mysql_fetch_array($result)) { print " "; print $row["candidate"]; print ": "; print $row["votescast"]; print " "; } ?>
12
Visit site sharon.ns.purchase.edu/jeanine/flashtest/flashtophp2.html ALSO sharon.ns.purchase.edu/jeanine/flashtest/showvotes.php
13
Homework PROJECTS! Will post guide to final quiz
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.