开发者

Loading var from PHP script using flash

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 foll开发者_C百科owing 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜