PDA

View Full Version : pass var from php to swf (twice kind of)



matthewk
October 25th, 2005, 02:15 AM
I am trying to pass var pid into index.php which embeds the swf. I am trying to get the swf to take that var pid and request pos.php which has the php db connection/query code, and I need to get those vars from the pos.php back into pos.swf. Please help! I know it looks a little messy; I've been trying to figure it out by looking at different guides on this. Thanks in advance!

index.php?pid=1


<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="525" height="355" id="pos" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="pos.swf" />
<param name="FlashVars" value="pid=<?php echo $_GET['pid'];?>">
<param name="quality" value="high" />
<param name="bgcolor" value="#E6E2B9" />
<embed src="pos.swf" quality="high" bgcolor="#E6E2B9" width="525" height="355" name="pos" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>


pos.swf


this.onLoad=function(){
allinvis();
}

myLoad = new LoadVars();
myLoad.path = this;
myLoad.pid = _root.pid;
myLoad.onLoad = function(success)
{
if(success){
#include "whatvis.txt"
} else {
trace("PHP PAGE NOT FOUND");
}
};
myLoad.SendAndLoad("pos.php", myLoad , "GET");


pos.php


<?php
$link = @mysql_connect("localhost", "username", "password")
or die("Could not connect" . mysql_error());
$db = @mysql_select_db("dbname",$link) or die("Could not
select database");

$query = "SELECT * FROM p WHERE pid = '".$pid."'";
$result = @mysql_query($query,$link) or
die("Could not submit query");

$tmp = mysql_fetch_array($result);

print "&s1=".$tmp[s1];
print "&s2=".$tmp[s2];
print "&loading=NO";

mysql_close($link);
?>

evilgoo
October 25th, 2005, 02:55 AM
First, you need two LoadVars variables, one for the information you are sending out from the Flash and another for the info you are getting from the PHP. For instance, you can make a var called LvOut to send data from the Flash to the PHP. And, make another var called LvIn to recieve the new data from the PHP. Also, you should be using the POST method instead of GET in that SendAndLoad function. I suggest you take a look at www.gotoandlearn.com (http://www.gotoandlearn.com/) tutorial on PHP, MySQL, and Flash. Here is some ActionScript code I wrote for a project that might help...

onClipEvent (load)
{

lvOut = new LoadVars();
lvIn = new LoadVars();

lvIn.onLoad = function (success)
{
_root.questions.questionsbx.text = lvIn.qinput;
_root.qid.qidbx.text = lvIn.qidinput;
_root.count.countbx.text = lvIn.countinput;
}
lvOut.choice = _root.category_mc.category_cb.choice;
lvOut.sendAndLoad(path + "questions.php", lvIn, "POST");
}

matthewk
October 27th, 2005, 02:01 AM
I still haven't gotten this to work the way I need to. The only thing I have managed if I load http://.../pos.swf?pid=1 then the dynamic textfield with var pid will display the '1'.
Basically, I want to submit url such as http://.../pos.php?pid=1 and pos.php selects data from db where pid = 1. I want then for the data from the db to be pushed into the swf. I can't figure out how to send a var into the swf; also, I can't figure out how to do this and keep odd print statement from showing on my php which shows the swf. I've tried this from many resources including the above example. And, the one from the tutorial website noted above.

matthewk
October 27th, 2005, 03:16 AM
http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_16417
I was missing the vars from the embedded tag :( works now.