views:

55

answers:

1

Hi All,

I am trying to get a var from a PHP script running on my web server and from every forum post I have read, what I am doing should be working. I have the following:

var lvContent = new LoadVars();
lvContent.load("http://{MY_DOMAIN}/Includes/getID.php");                
trace("ID: " + lvContent.pageID);       

The problem is that ID in the trace is always undefined.

I have tried the following in the php file:

<?php
echo "pageID=29";
?>

This is a small test to try and get it working but I cannot seem to.

Am I doing something wrong?

Thanks in advance for the help.

I am using ActionScript 2.0

A: 

Flash uses non-blocking communication with a server, this means that the code you put after lvContent.load (in your case "trace") is executed immediately while the load action has not yet finished.

To get your code working you need to use a callback function:

var lvContent = new LoadVars();
lvContent.onLoad = function(success) {
   if(success) {
       trace(lvContent.pageID);
   }else{
       trace("load error");
   }
};
lvContent.load("http://{MY_DOMAIN}/Includes/getID.php");                
trace("ID: " + lvContent.pageID); 

In the case you just saved some space by not supplying this piece of code. I also think you need to start your URL variables with a & so:

<?php
echo "&pageID=29";
?>

See the example here.

Les
Thanks for the comment. I have tried this method but it didn't work. When I am debugging, it won't break on anything in the onLoad method.
webnoob