Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

From AS3 write STRING to txt file with PHP

Explorer ,
Apr 16, 2018 Apr 16, 2018

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?

TOPICS
ActionScript
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Apr 17, 2018 Apr 17, 2018

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

...
Translate
Explorer ,
Apr 17, 2018 Apr 17, 2018

oh now it works!!!!!!

but everything i get to same line and '/n' i get like text in the string.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 17, 2018 Apr 17, 2018

use double quote in PHP since single quote just litteraly print everything

so replace '\n' to "\n"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2018 Apr 17, 2018

oh ok works good. i changed ' /n' to "/n"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 17, 2018 Apr 17, 2018

Now i don`t know witch answer to mark as correct:)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 17, 2018 Apr 17, 2018

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

}

?>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 17, 2018 Apr 17, 2018
LATEST

Please mark my last comment as correct answer to help other further users thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines