View Full Version : Using Flash and PHP
njoay
October 24th, 2007, 05:48 PM
Hello,
I'm having trouble integrating PHP with Flash. To avoid this:
files.php?group_id=1234&num=1
how do incorporate group_id=1234 within my files.php file? I've tried adding &group_id=1234&num=1 at the very beginning of my files.php file but my flash doesn't recognize it and tells me that it that it is undefined.
Any help to solve this issue would be greatly appreciated.
Thanks
spazcer
October 24th, 2007, 06:05 PM
are u trying to get flash to read the variable or pho to read it from flash
njoay
October 24th, 2007, 06:39 PM
Hi spazcer,
Thanks for your reply. I'm trying to get flash to read the variable. Is it a matter of simply creating a php file specifically named: ?group_id=1234&num=1.php?
Any help is greatly appreciated!
spazcer
October 24th, 2007, 06:41 PM
when you embed the swf into your HTML just append the variables to the end of it
myflash.swf?group_id=1234&num=1.php
then u can access the variables as group_id and num right in flash
njoay
October 24th, 2007, 07:09 PM
Spazcer,
Hmm...I think I understand you correctly but not too sure. Where do I actually embed
myflash.swf?group_id=1234&num=1.php" in Dreamweaver?
What I'm trying to do is call the variable group_id=1234&num=1 from a button in flash. The button then reads the info in my files.php but not from the group_id=1234&num=1.php file. I'm trying to have the "group_id=1234&num=1" variable to be read by the files.php file.
What if I'm trying to read the php from flash?
Thanks again
RubenFlash
October 24th, 2007, 08:05 PM
Use the send method. When you click the button...
myButton.onRelease = function(){
var sendObj:LoadVars = new LoadVars();
sendObj.group_id = 1234;
sendObj.num = 1;
sendObj.send("myPhp.php", "_blank", "post");
}
njoay
October 29th, 2007, 03:57 PM
RubenFlash,
thanks for the AS! I have set the AS similarly to what you provided but my swf does not play properly in Flash, although it plays ok when I publish it in HTML. Am I doing something wrong or does PHP and Flash not work well together only when previewing it as an swf?
Thanks again!
RubenFlash
October 29th, 2007, 06:45 PM
RubenFlash,
thanks for the AS! I have set the AS similarly to what you provided but my swf does not play properly in Flash, although it plays ok when I publish it in HTML. Am I doing something wrong or does PHP and Flash not work well together only when previewing it as an swf?
Thanks again!
On order to preview in Flash autoring environment you need to provide the full path to the php file, like this:
sendObj.send("http://localhost/myFlashFolder/myPhp.php", "_blank", "post");
njoay
October 29th, 2007, 07:28 PM
RubenFlash,
thanks so much! another issue that i'm having is that each button calls a separate php file with only a different argument. So I would like button 1 to call files.php?group_id=1234&num=1 and button 2 to call files.php?group_id=5678&num=1.
Currently I'm saving each php argument file as 1234&num=1.php and 5678&num=1.php but button 1 & 2 refers to the same 1234&num=1.php file.
Any suggestions as to why?
Thanks again!
RubenFlash
October 30th, 2007, 09:37 PM
You can use the same php. Just pass a diferent num:
function sendToPhp(group_id){
var sendObj:LoadVars = new LoadVars();
sendObj.group_id = group_id;
sendObj.num = 1;
sendObj.send("myPhp.php", "_blank", "post");
}
myButtonA.onRelease = function(){
sendToPhp(1234);
}
myButtonB.onRelease = function(){
sendToPhp(5678);
}
njoay
October 31st, 2007, 06:42 PM
RubenFlash,
Thanks so much for your responses. They are very helpful, but I'm still facing some problems. So do I save the each php file as "files.php?group_id=1234&num=1" and "files.php?group_id=5678&num=1"
Nothing seems to be working so I'm not sure what exactly seems to be the problem.
Additional help is always appreciated!
RubenFlash
October 31st, 2007, 09:11 PM
Save your php files with any name, for example, "myPhp.php" and place them in the same directory as your flash files. Then, just use the actionscript I provided in order to comunicate with your php. You don't need to pass variables in the name of your php's.
njoay
November 1st, 2007, 05:14 PM
RubenFlash,
Can you clarify a little further? If I can give my main php file any name then how will flash now which group_id to call?
The contents of my files.php?group_id=1234&num=1 are:
&image1=p1.jpg&img_w1=613&img_h1=460&thumb1=THUMB1 p1.jpg&image2=p2.jpg&img_w2=613&img_h2=460&thumb2= THUMB1p2.jpg&count=2&group_id=1234&num=1
And the contents of my files.php?group_id=5678&num=1 are:
&image1=p1.jpg&img_w1=613&img_h1=460&thumb1=THU MB1 p1.jpg&image2=p2.jpg&img_w2=613&img_h2=460&thumb2= THUMB1p2.jpg&count=2&group_id=5678&num=1
When I click on the first button which calls group_id=1234, it works. But when I click on group_id=5678 settings of the group_id=1234 still appears. What else can I do?
Thanks for all your help!
RubenFlash
November 2nd, 2007, 04:07 PM
njoay, you need to understand a little bit better how the php-flash interaction works, because the php files don't work like that. The php content would be something like this:
echo "These are the flash variables that I sent:\n";
echo $_POST['group_id']."\n";
echo $_POST['num']."\n";
and the flash...
function sendToPhp(group_id){
var sendObj:LoadVars = new LoadVars();
sendObj.group_id = group_id;
sendObj.num = 1;
sendObj.send("myPhp.php", "_blank", "post");
}
myButtonA.onRelease = function(){
sendToPhp(1234);
}
myButtonB.onRelease = function(){
sendToPhp(5678);
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.