View Full Version : PHP and Flash
fifty
April 22nd, 2007, 11:06 AM
Hello folks,
The title to this may be misleading.. but, I will get right to the point.
I have a Flash swf that is set up to send variable to a PHP script which, in turn adds the information to text file (.txt) in a guestbook that needs to be read by another flash movie.
Everything is working. I know this... but... in order to make it more flexible, I need the PHP to add a variable that I set, at the beginning of the text document. Right now, the text displays great if I send it to the flash file by calling on the PHP.... but I would rather have the text file load into the flash directly... to get it to work, I need to add a variable....
this is what the php is sending (example)
$Input = "Info: $Information";
So what I need to do is add something like
theVariable=
this will allow me to load the text file without the php (as there are some limitations)
I tried adding the variable to the text file by adding it like this:
$Input = "theVariable= Info: $Information";
which writes the words "theVariable=" to the file, thus allowing me to read it in the other flash file.
however, the php script is "adding" to the text file, so that it keeps getting bigger, like a guestbook... so.. If I use the above method, every new entry will start with my variable, but will only display the most recent entry.
Any ideas?
Thanks in advance... sorry for the long winded explaination..
phorte
April 23rd, 2007, 09:01 AM
hmmmm, thought i understood it there for a moment, but a tad bit confused now. So you have 1 txt file with all the guestbook data? how is that laid out at the moment? You are passing variable from flash to the php, then writing this data to the txt file. Are you simply over writing the existing data in the txt file? or do you wish to add more data to the txt file.
Then another flash movie is loading the data directly from the txt file.
I think if you are planning to have multiple data in the txt file. You will have to print to the txt file from php in a format similar to this: theVariable = "entry1||entry2||entry3";
such that || becomes a delimiter which you split the string in flash with, to seperate the entries. Then when you are wanting to add more data with the php, you will have to load the txt file, concat the "theVariable = " part, and then just add "||entry4" to the existing string.
Hmmm, sounds quite long winded it know. Maybe xml might be a better solution?? Especially if your planning on having a number of guestbook entries. Mabye even using mySQL would be even better. But yes, even more a headache.
Anyway, let me know what you think about all that, or if ive gone off on a tangent. A look at your codes would be helpful.
-Phorte.
fifty
April 30th, 2007, 08:40 AM
I was sick so it has taken me a while to get back and reply to this.. but...I will clarify the situation as it sounds like you may know ow to help me.
I have a flash movie (control panel) that I can log into and "edit" the text of another flash movie.
Basically... the control panel allows me to type some new text and hit send, which activates the PHP scripts... which in turn writes directly to a .txt file. Another flash movie is then reading from that .txt file when a user goes to the "news" area.
I mentioned the "guestbook" concept, because it is functioning like a guestbook in the way that the new info is being added to the beginning of the other entries.
But.. what I need to do.. and this will solve all of my problems...
I need to have a constant variable at the beginning of the text file that never changes.
I found another PHP script that performs the same function except that it adds the new entries to the bottom of the previous entries.. however.. it DOES keep a variable fixed to the very beginning of the text file. Problem is I don't know PHO well enough to try and integrate portions of both files.
thanks again!
any ideas?
phorte
April 30th, 2007, 09:12 AM
ah i see. Hmmm well im thinking maybe xml might be better to use?? i just find xml some much easier for small data storage applications. But if thats not possible, txt would still be fine.
If i could take a squizz at the php codes you are using im sure i could help you out. :)
fifty
April 30th, 2007, 09:45 PM
thanks for trying to help.
The PHP code I am using is from a guestbook script created by a fellow called jeff hill. However, I have altered the flash and some of the scripts to suit a different purpose - a news editor. The news editor I had built requires that the user edits the .txt file from one swf, while another swf (on the actual website) will load the .txt file and read it back... hence the need for the variable to be at the beginning of the text in the text file.
so.. I basically need the PHP script to always write the new info after the variable... so the text file will always begin with:
newsText=
so.. here's the PHP script:
$Submit = $_POST["Submit"];
$TITLE = $_POST["TITLE"];
$newsText = $_POST["newsText"];
$Website = $_POST["Website"];
$NumLow = $_REQUEST["NumLow"];
$NumHigh = $_REQUEST["NumHigh"];
$TITLE = ereg_replace("[^A-Za-z0-9 ]", "", $TITLE);
$newsText = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $newsText);
$Website = eregi_replace("http://", "", $Website);
$Website = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $Website);
$TITLE = stripslashes($TITLE);
$newsText = stripslashes($newsText);
$Website = stripslashes($Website);
// ################################################## #################################
// ########## Reading and Writing the new data to the GuestBook Database #############
if ($Submit == "Yes") {
// Next line tells the script which Text file to open.
$filename = "infoFiles/newsInfo.txt";
// Opens up the file declared above for reading
$fp = fopen( $filename,"r");
$OldData = fread($fp, 80000);
fclose( $fp );
// Gets the current Date of when the entry was submitted
$Today = (date ("l dS of F Y ( h:i:s A )",time()));
// Puts the recently added data into html format that can be read into the Flash Movie.
$Input = "Name: <b>$TITLE</b><br>Email: <b><u><a href=\"mailto:$Email\">$Email</a></u></b><br>Website: <b><u><a href=\"http://$Website\" target=\"_blank\">$Website</a></u></b><br>Comments: <b>$newsText</b><br><i><font size=\"-1\">Date: $Today</font><br><br>.:::.";
/* This Line adds the '&GuestBook=' part to the front of the data that is stored in the text file. This is important because without this the Flash movie would not be able to assign the variable 'GuestBook' to the value that is located in this text file */
$New = "$Input$OldData";
// Opens and writes the file.
$fp = fopen( $filename,"w");
if(!$fp) die("&newsInfo=cannot write $filename ......&");
fwrite($fp, $New, 800000);
fclose( $fp );
}
// ################################################## #################################
// ######### Formatting and Printing the Data from the Guestbook to the Flash Movie ##
// Next line tells the script which Text file to open.
$filename = "infoFiles/newsInfo.txt";
// Opens up the file declared above for reading
$fp = fopen( $filename,"r");
$Data = fread($fp, 800000);
fclose( $fp );
// Splits the Old data into an array anytime it finds the pattern .:::.
$DataArray = split (".:::.", $Data);
// Counts the Number of entries in the GuestBook
$NumEntries = count($DataArray) - 1;
print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&newsInfo=";
for ($n = $NumLow; $n < $NumHigh; $n++) {
print $DataArray[$n];
if (!$DataArray[$n]) {
Print "<br><br><b>No More entries</b>";
exit;
}
}
?>
phorte
May 1st, 2007, 09:17 AM
well, pretty much all i think you need to change is this line.
$New = "$Input$OldData";
to this.
$New = "newsText=$Input$OldData";
not 100% is this is what u are fully meaning, as im having a bit of trouble seeing the layout of the output to the txt file without the other flash files. If its alrite i wouldnt mind seeing all the files, just so i can get a better grasp on it. Also, i would seriously consider looking at xml for this, cause at the moment, that data is in a very 'data friendly' format, with all the html around it. An xml format to this:
<news>
<story>
<title>Story 1</title>
<email>asd@asd.asd</email>
<website>http://www.asd.com</website>
<comment>Here is the comment</comment>
<date>1/5/07<date>
</story>
<story>
<title>Story 2</title>
<email>qwe@qwe.qwe</email>
<website>http://www.qwe.com</website>
<comment>another comment</comment>
<date>30/4/07<date>
</story>
.
.
.
</news>I just feel it would allow for the data to be stored in much smarter way, and allow you to have more control over its format and display in flash. Buts it up to you i guess.
-Phorte
fifty
May 1st, 2007, 08:32 PM
Hey Phorte, thanks again for your help on this. Its making progress!
I would switch to XML... but.. I am unfamilar with it and kind of want to see this through right now just to get it functional... then I will jump into exploring XML. (if you can siggest a good tutorial.. would be much obliged.)
The change you suggested allows the other swf to properly read the txt file... but it writes the "newsText=" variable before every entry... while it would be ideal if it would write it to the very beginning of the text file and write the new entries after it.
I found another PHP file that works the way I wish this one would.. EXCEPT it writes the newest entries to the bottom of the text file, whereas the one I showed you writes it to the top so that the viewer sees the newest entry first. The other PHP file writes everything after a pre-existing variable ("gb=") that is set in the text file. I have pasted this other PHP code below for you to see what I mean. I have been playing with both files to try and get the first one to work the way I want it.. or to try and get the second one to write the new entries to the beginning... but.. I am by no means a PHP coder... though I am starting to learn a few things.
$filename = 'gb.txt';
$gb = "gb=";
$date = (date ("m/d/y h:i A",time()));
$datetwo = "Date: ";
$name = $HTTP_GET_VARS['name'];
$nametwo = "Name: ";
$email = $HTTP_GET_VARS['email'];
$emailtwo = "Email: ";
$message = $HTTP_GET_VARS['message'];
$messagetwo = "Message: ";
$somecontent = "$nametwo$name\n$emailtwo$email\n$datetwo$date\n$me ssagetwo$message\n\n";
$New = "$Input$OldData";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
exit;
}
fclose($handle);
}
?>
... would be great if you had any more ideas... I will keep on trucking till this works... and then try out the XML as you suggested..
Thanks again!
r
phorte
May 4th, 2007, 01:36 AM
hi there again, ive been doin a bit of research into flash/php/xml connections, and im thinking its goin to be much easier then having to deal with txt file.
At the moment, the bulk to the data processing is being done by the php. Individual variables are transerfed from ur admin panel to the php. The php is then formating all that, into 1 string, and concatting it with the rest of the variables in the txt and outputting it as a new txt will the appended data.
Then ur display swf is loading up the txt file, and has to decipher all the variables from that, by spliting the string and such.
Im proposing a new method where.
Admin Panel loads all the existing data from an xml. You add you new entry into an xml object within the flash. Then that xml object is passed to the php, which turns it into a xml file. Then your display swf loads the xml file and can easily locate all the data to display because its in xml format.
Therefore in this format the php meerly becomes a data exchange to convert the flash xml object and xml file. not a long winded data encoding from string variables to one 1 txt file.
Dont worry too much about understanding all of that. Im gonna mess around a bit and see if i can rig up an example for you. Gimmie a day or so.
-Phorte
fifty
May 4th, 2007, 05:35 PM
seriously... thank you for trying to help out... after reading your note, I have started trying to familiarize myself with the xml basics so that I am not completely in the dark. I look forward to learning something that I probably should have learned three years ago.
r
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.