Copy link to clipboard
Copied
I have problem.
My AS3 code:
submit_btn.addEventListener(MouseEvent.CLICK, writeLine);
function writeLine(e:MouseEvent):void{
var my_vars:URLVariables = new URLVariables();
my_vars.kazkas1_t = kazkas1.text;
my_vars.kazkas2_t = kazkas2.text;
my_vars.kazkas3_t = kazkas3.text;
var my_url:URLRequest = new URLRequest("http://www.mesmylimbirzus.lt/app/id.php");
my_url.method = URLRequestMethod.POST;
my_url.data = my_vars;
var my_loader:URLLoader = new URLLoader();
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
my_loader.load(my_url);
kazkas3.text = "Išsaugota";
}
and PHP code:
<?php
$myfile = fopen("test.txt", "a")
$current = ($_POST['kazkas1_t'] . " " . $_POST['kazkas2_t'] . $_POST['kazkas3_t'] .'\n');
fwrite($current .'\n');
?>
But i GET error:
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
WHAT IM DOING WRONG?
1 Correct answer
correct answer:
function writeLine(e:MouseEvent):void{
var my_url:URLRequest = new URLRequest("http://www.mesmylimbirzus.lt/app/id.php");
my_url.method = URLRequestMethod.POST;
my_url.data = "kazkas1_t="+kazkas1.text+"&kazkas2_t="+kazkas2.text+"&kazkas3_t="+kazkas3.text;
var my_loader:URLLoader = new URLLoader(); try { my_loader.load(my_url); } catch (error:Error) { trace("Unable to load requested document."); }
}
private function configureListeners(dispatcher:IEventDi
Copy link to clipboard
Copied
oh now it works!!!!!!
but everything i get to same line and '/n' i get like text in the string.
Copy link to clipboard
Copied
use double quote in PHP since single quote just litteraly print everything
so replace '\n' to "\n"
Copy link to clipboard
Copied
oh ok works good. i changed ' /n' to "/n"
Copy link to clipboard
Copied
Now i don`t know witch answer to mark as correct:)?
Copy link to clipboard
Copied
correct answer:
function writeLine(e:MouseEvent):void{
var my_url:URLRequest = new URLRequest("http://www.mesmylimbirzus.lt/app/id.php");
my_url.method = URLRequestMethod.POST;
my_url.data = "kazkas1_t="+kazkas1.text+"&kazkas2_t="+kazkas2.text+"&kazkas3_t="+kazkas3.text;
var my_loader:URLLoader = new URLLoader(); try { my_loader.load(my_url); } catch (error:Error) { trace("Unable to load requested document."); }
}
private function configureListeners(dispatcher:IEventDispatcher):void { dispatcher.addEventListener(Event.COMPLETE, completeHandler); dispatcher.addEventListener(Event.OPEN, openHandler); dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler); dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);}private function completeHandler(event:Event):void { var loader:URLLoader = URLLoader(event.target); trace("completeHandler: " + loader.data);}private function openHandler(event:Event):void { trace("openHandler: " + event);}private function progressHandler(event:ProgressEvent):void { trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);}private function securityErrorHandler(event:SecurityErrorEvent):void { trace("securityErrorHandler: " + event);}private function httpStatusHandler(event:HTTPStatusEvent):void { trace("httpStatusHandler: " + event);}private function ioErrorHandler(event:IOErrorEvent):void { trace("ioErrorHandler: " + event);}
---------------
my php:
<?php
$fp = @fopen("test.txt", "a");
if($fp){
$current = $_POST['kazkas1_t'] . $_POST['kazkas2_t'] . $_POST['kazkas3_t'] ."\n";
if(@fwrite($fp,$current)){
// ok
}else{
// debug issue
}
fclose($fp);
}else{
// answer to flash by something like varNamer=error to tell the flash client that something wrong happen
// or send and email to yourself to debug it
}
?>
Copy link to clipboard
Copied
Please mark my last comment as correct answer to help other further users thanks


-
- 1
- 2