0

Im trying to fetch some data from PHP and use it in a link in flash AS3.

flash code:

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,onLoaded);
loader.load(new URLRequest("FLA_connect.php"));
var variables:URLVariables = new URLVariables();
signup.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick);

function onLoaded(evt:Event):void
{
var data:URLVariables = new URLVariables(evt.target.data);
variables.sponny = data.spon;


}

function mouseClick(event:MouseEvent):void
{
navigateToURL(new URLRequest('http://www.website.com/'+variables.sponny),"_self");
}

FLA_connect.php code:

<?php

require ('config.php');

print "spon=$username";

?>

I've tested FLA_connect.php and it returns the correct data but when tested in flash, the variable returns as undefined so i end up with a link www.website.com/undefined.

Any ideas guys??

thanks

For shanethehat

<?

require ('../config/db_4554651684654548784216.php'); //DB connection info is stored
require ('conf_id.php'); //this file holds the value for $lead_reference

mysql_connect($hostname,$username,$password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$get__id_check = mysql_query("SELECT * FROM $usertable WHERE ". "idEmail_lead = '$lead_reference'");

while($id__check = mysql_fetch_array($get__id_check)) {
    $first_N = $id__check["First_Name"];
    $last_N = $id__check["Last_Name"];
    $email_add = $id__check["Email"];
    $GDI__username = $id__check["GDI_Username"];


 }


?>
1
  • i recommend to use FireBug whenever there is a functionality like getting parameters from server side pages. in FireBug got to Net->HTML, you will get all request parameters and response parameters... hope it helps :) Commented Aug 25, 2011 at 6:11

3 Answers 3

2

I my self have hit this error and problem. I have checked rechecked and recoded the script 5 times thinking that it was my fault or a code was wrong. I have figured out what part of the code gives the undefined variable. Its in the result function area.

function showresult(event:event) {
 txtbox.text = "" + event.target.data.spon;
}

or what ever. the code spon is not defined in the even.target.data part which causes a undefined error. Now for me I changed the event.target.data.myresult to event.target.data and was able to see the php file text.

But was unable to get response back from the file when adding the myresult to it. If anyone has any other useful information regarding this problem please let me know. I also did try toString added onto the myresult but it gave a massive error and again pointing to the undefined myresult.

Sign up to request clarification or add additional context in comments.

1 Comment

I actually worked out the problem for this issue. It was quite a silly one. Flash doesn't like any additional chars in the response text (including white spaces, line breaks, etc etc), a bit like JSON. The reason why the error was only occurring when I included that file was because I had a line break after my php closing tag (?>), in that included file, which caused a line break to appear in the response text. That was the problem. Are you echoing/printing any additional chars? White spaces? Line breaks? If so, remove them.
1

Have you tried just accessing the variables in data directly? You will also need to tell your loader to expect URL encoded variables:

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE,onLoaded);
loader.load(new URLRequest("FLA_connect.php"));

function onLoaded(evt:Event):void
{
    (ExternalInterface.available) ? ExternalInterface.call("console.log","Incoming data:" + evt.target.data) : trace("Incoming data:" + evt.target.data);
    variables.sponny = evt.target.data.spon;
}

Failing that, start by tracing the value of evt.target.data to make sure you are getting something back from PHP, and that you are waiting long enough for the data to return before clicking the sign up button.. To be completely safe it might be better to only reveal the sign up button when the data is loaded

9 Comments

Hey, I cant use trace as i don't have a local server setup but i have managed to work out whats causing the issue, but it doesn't make any sense. In the php file i have included a file (config.php). When i do not include that file and just use something like "<? print spon="test"; ?>" it will work. But when i include the file but dont use any variables in the included file eg: "<? include ('config.php'); print "spon=test"; ?> it wont work. So i know the cause of the issues is including the config.php file. But i don't understand why... I have checked over config.php and it seems to be fine.
I've also just setup a frame so the signup button will only be shown once the data has been received, but it's still doing the same thing. Really appreciate your help!
In your question you use require(). That will cause the script to fail completely if config.php is not found, whereas include() will only give an error. What do you see if you enable error reporting and browser to FLA_connect.php in your browser?
I see the correct information when FLA_connect.php in my browser (spon=myusername). How would i enable error reporting? thanks.
Put these lines into your PHP: error_reporting(E_ALL); ini_set('display_errors', 1);, although you must remove these when you deploy your application to live. Can you update your question with the contents of config.php?
|
0

If including the config.php is cause it to fail then you have an error in your config file
Call up HTTP://myserver.com/FLA_connect.php directly from a browser
You should see the erorr report

Now for the second part or your problem
In your php page
You are returning a string

spon=XXXXXXX

And as such your should parse it as a string on the actionscript side and not as an object.

3 Comments

Hey, I have attempted to call all required files (config.php, and all required in config.php (see my edits in the question)), none of them report any errors and work fine (do what they should do). How would i parse it as a string on AS3? I've parsed it like this before without any issues.
Personally I convert data with a key=value structure into a json object and encode it before sending it off to the flash client. Then in the actionscript i import the as3crypto library and json.decode it.
call up HTTP://myserver.com/FLA_connect.php from a browser and see what you get

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.