user849137
user849137

Reputation:

flash AS3 returning undefined variables from PHP

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"];


 }


?>

Upvotes: 0

Views: 2340

Answers (3)

Demon
Demon

Reputation: 21

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.

Upvotes: 2

shanethehat
shanethehat

Reputation: 15580

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

Upvotes: 1

The_asMan
The_asMan

Reputation: 6403

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.

Upvotes: 0

Related Questions