Current location: Hot Scripts Forums » Programming Languages » PHP » flash to php


flash to php

Reply
  #1 (permalink)  
Old 03-24-05, 01:06 PM
feffik feffik is offline
Newbie Coder
 
Join Date: Mar 2004
Location: NL
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
flash to php

Hi, sup?

-ingredients-
flash movie
php file
mysql db.

-result-
Does anyone here know how to execute a php script from within a flash movie?
and how to send variables from the flash movie, to a different php script.
which inserts the code in the mysql db.

thnx.
Reply With Quote
  #2 (permalink)  
Old 03-24-05, 01:16 PM
PromptLogic PromptLogic is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Check out PHPObject. It does exactly that. It's kind of like fake remoting.

http://ghostwire.com/go/28

It's free, LGPL (I believe) and includes samples to get you started.
Reply With Quote
  #3 (permalink)  
Old 03-24-05, 01:27 PM
feffik feffik is offline
Newbie Coder
 
Join Date: Mar 2004
Location: NL
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Is there not an easy way, without installing addictional stuff???
Reply With Quote
  #4 (permalink)  
Old 03-24-05, 02:12 PM
PromptLogic PromptLogic is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, we can do it another way without extensions.

I will write a little tutorial to hopefully explain a simpler process. In this example, we will have a 3 Frame move. On frame 1 you will have your main interface with buttons, textboxes and whatever. Extend it so that Frame 1 is visible on frame 2 and frame 3. Except on frame 2 and frame 3, add a label that says "Communicating with Server".

Now, on frame one, you need to add an action to a button to initiate the call. You will also want to check your variables here before sending it but I'll leave that up to you. Also, flash sends all the variables that are local in your movie. You do not need to tell flash what variables to send.

So, put an action on the onclick event of your button:

Code:
on (release) { 
loadVariablesNum ("yourscript.php", 0, "POST");
gotoAndPlay(2);
}
This will initiate the call and move on to frame 2 to start the loop while we're waiting on data to be returned. Remember, that function executes and continues. The movie does not wait for the result but rather continues on. So, if you are wanting a result from your php page before continuing then you need to create a loop.

On frame 3, add this action to the frame:

Code:
if (loading eq "YES") {
gotoAndPlay (2);
} else {
 gotoAndStop (1);
}
That loop will continue moving from frame 2 to frame 3 until the loading is done. Once the loading is done, it will go to frame 1 and stop.



Now on the PHP side you will receive the variables just as they are named in your flash movie. So if you have two textboxes in your movie with vaiable names as textbox1 and textbox2, in php you would get that value like this:

PHP Code:

global $HTTP_POST_VARS;

$mytext1 $HTTP_POST_VARS["textbox1"];
$mytext2 $HTTP_POST_VARS["textbox2"]; 
OR

PHP Code:

$mytext1 $_POST["textbox1"];

$mytext2 $_POST["textbox2"]; 

You do that for all your variables that you want to use from the Flash movie. From there you execute your database code and any other code. For brevietivity, I will assume you know that.

To return variables to the flash movie, you just need to print out the variables in this way.

lets say we have three variables that we want to return. One, $myresult, could say whether whatever action we did was successful, the other two could be the textbox1 and textbox2 variables. For lack of a better example, we'll just change the textbox1 and textbox2 values to return "Hello textbox1!" and "Hello textbox1!" respectivly.

example:

PHP Code:

$myresult "Success!";

$mytext1 "Hello textbox1!";
$mytext2 "Hello textbox2!";

print 
"&myresult=" $myresult "&textbox1=" $mytext1 "&textbox2=" $mytext2
Your flash movie will now have the variable myresult in its scope.

If you need furthur help just let me know. It's been a while since I have done it this way. Also, this is for Flash 5 as most people use this version but is similair in MX.

Regards

Last edited by PromptLogic; 03-24-05 at 02:35 PM.
Reply With Quote
  #5 (permalink)  
Old 03-24-05, 02:30 PM
filth filth is offline
Newbie Coder
 
Join Date: Mar 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
cool thanks for the guide althogh I want the peson who posted the request this will come in very handy was looking how to do this ages ago but was unable to find anything
Reply With Quote
  #6 (permalink)  
Old 03-26-05, 11:36 AM
feffik feffik is offline
Newbie Coder
 
Join Date: Mar 2004
Location: NL
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
thnx

thnx for the reply,

I made a contact form in flash some time ago. It worked fine.

But I was trying to access a mysql database, later on. But it seemed like nothing got throut to the php script.

I think it's bcuz i didnt use the 3 frame style in the last movie. (which i did in the contact form).


Maybe that was the reason it didn't work.

thanks for the reply, hope i'll get it to work now.
Reply With Quote
  #7 (permalink)  
Old 03-26-05, 12:15 PM
feffik feffik is offline
Newbie Coder
 
Join Date: Mar 2004
Location: NL
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Hi, I got another question.

I think I know what the problem was.
I didn't use the webserver when I tested the movie.
And when I did, it worked.

Now the question, It ain't possible to run a php script without the webserver ?

How can I get the variables into a database, without having to install a webserver?

pls help.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
flash mx to PHP to flash mx olm75 PHP 1 12-09-04 03:44 AM
setting PHP sessions in flash phizzlecom PHP 1 11-08-04 08:20 PM
Php with flash or without tables ? EraseR PHP 0 06-26-04 07:36 AM
php into flash??? j0hnbanks PHP 1 06-11-04 11:53 AM
Fast growing RPG site seeks PHP or Flash programmars lanzer Job Offers & Assistance 7 03-06-04 05:00 PM


All times are GMT -5. The time now is 05:38 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.