Skip to main content
oliversen
Inspiring
April 3, 2018
Answered

Getting information from php file

  • April 3, 2018
  • 1 reply
  • 1119 views

The output of my php file looks like this:

[{"id":2,"name":"NRK MP3","url":"http:\/\/lyd.nrk.no\/nrk_radio_mp3_mp3_m","country_id":37},{"id":72,"name":"Radio Loland","url":"http:\/\/stream.radiololand.no:5000\/loland128","country_id":37}]

What i want to accomplish is to get that information, I need the url, the country id, the name, and the id. But I get this 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 DatabaseTest_fla::MainTimeline/onCompleteHandler()[DatabaseTest_fla.MainTimeline::frame1:28]

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at flash.net::URLLoader/onComplete()

If I change my php file to this. It works

<?php

   echo "values=8";

?>

My As3 code:

import flash.events.MouseEvent;

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.net.URLVariables;

import flash.net.URLLoaderDataFormat;

import flash.net.URLRequestMethod;

import flash.events.Event;

var myLoader:URLLoader = new URLLoader();

myLoader.dataFormat = URLLoaderDataFormat.TEXT;

var myRequest:URLRequest=new URLRequest("mydomain.com/something.php");

myLoader.load(myRequest);

myLoader.addEventListener(Event.COMPLETE,onCompleteHandler);

var myValue: String;

function onCompleteHandler(e:Event):void{

          var myvariable: URLVariables = new URLVariables(e.target.data);

         myValue = myvariable.values;

                  trace(myValue);

}

This topic has been closed for replies.
Correct answer Robert Mc Dowell

Hmm, tried both evt.target.data, event.target.data, and e.target.data.

Same result unfortunately:

id: undefined


add json.dataFormat = URLLoaderDataFormat.TEXT;

and put back json.data to parse;

trace(json.data);

if it's still undefined so the problem comes from your php script or security sandbox network

you should test on your same domain server

1 reply

Robert Mc Dowell
Legend
April 3, 2018

You must use JSON class as it's a JSON structure.

JSON - Adobe ActionScript® 3 (AS3 ) API Reference

and use JSON.parse(e.target.data)

oliversen
oliversenAuthor
Inspiring
April 7, 2018

Thank you for replying Robert,

I have tried a little back and forth now.

This is my code:

var json:URLLoader = new URLLoader();

var parsedJSONData:Object;

   json = new URLLoader();

   json.addEventListener(Event.COMPLETE, parseJSON);

   json.load(new URLRequest("http://blogglista.no/TESTESTDBDBDBDBD/check_media.php"));

   trace("Loading JSON file...");

  

function parseJSON(evt:Event):void {

   trace("JSON file loaded successfully!");

   trace("Parsing JSON...");

   trace("RESULTS:");

   parsedJSONData = JSON.parse(json.data)

  // var jsonArray:Array = (json.data);

   trace("id: " + parsedJSONData.Id);

}

This is what my Output looks like:

Loading JSON file...

JSON file loaded successfully!

Parsing JSON...

RESULTS:

id: undefined

Test Movie terminated.

Why is my "id" undefined?

My inital goal is to make a for loop for all my id's

Thank you

Robert Mc Dowell
Legend
April 7, 2018

json.data must be replaced with evt.target.data