First of all a big hello to all of you out there!
To the point…
I have a swf with 2 MCs (one for sendind vars to php and one for loading content from
a .txt), one input text box and one dynamic text box.
I want it to work as following:
Write a text to the text box, hit send button and it will send the var to the php
wich will create a .txt file with the text from the var. Then hit the load button and
it will load the .txt file wich was created, catch the var and show it to the dynamic
text box. Until now it works OK!
But… When i try to do it again and i write a different text to the input text box and
hit the send button it updates my .txt file as i can see from my ftp client but when i
hit again the load button it doesn’t load the updated .txt and it keeps showing me the
old content of the .txt in my dynamic text box…
pffff… i’ve tried everything and i would really appreciate any help!
Flash Code:
load_button.addEventListener(MouseEvent.CLICK, load_me_function);
function load_me_function(event:MouseEvent):void{
var loadWhat:String = new String();
loadWhat = "theload2.txt";
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
var myurlreq = new URLRequest(loadWhat);
myLoader.load(myurlreq);
myLoader.addEventListener(Event.COMPLETE, onDataLoad);
function onDataLoad(evt:Event){
dynamic_text.text = evt.target.data["Title"];
}
}
send_var_button.addEventListener(MouseEvent.CLICK, send_var_function);
function send_var_function(event:MouseEvent):void{
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("php_file.php");
varSend.method = URLRequestMethod.GET;
varSend.data = variables;
variables.var1 = input_text.text;
sendToURL(varSend);
}
Php Code:
<?php
$var1 = $_GET['var1'];
$ourFileName = "text_file.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
$stringData = "Title=$var1";
fwrite($ourFileHandle, $stringData);
fclose($ourFileHandle);
?>