将变量从 PHP 4 导入 Flash
我正在尝试从 PHP 脚本导入变量,然后再将其实现到更大的项目中。到目前为止我所得到的只是头痛。
// this is all thats in test.php other than the open and close brackets.
// Normally I'd have it doing a mysql_query and putting useful information into the print statement.
print( "lamegame.net/test/test.php?val=foo&id=0000&name=Glenn");
test.as 所要做的就是访问这三个变量。问题在于“val”未定义。然而 id 和 name 变量很好,分别返回 0000 和 Glenn。
package {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.*;
import flash.net.*;
public class test extends MovieClip
{
public function test()
{
super();
//prep request
//EDIT: sorry, I realize now it makes a bit of difference between test.php by itself and http://.../test.php.
var request:URLRequest = new URLRequest("http://somewebsite.com/test.php");
request.method = URLRequestMethod.GET;
var loader:URLLoader = new URLLoader();
//load request
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataLoaded);
loader.load(request);
}
public function dataLoaded(e:Event):void
{
var name = e.target.data.name;
var id = e.target.data.id;
var val = e.target.data.val;
trace("Val: " + val + "ID: " + id + " Name: " + name);
}
}
}
I'm trying to get variable importing from a PHP script before I implement it into a larger project. So far all I've gotten is headaches.
// this is all thats in test.php other than the open and close brackets.
// Normally I'd have it doing a mysql_query and putting useful information into the print statement.
print( "lamegame.net/test/test.php?val=foo&id=0000&name=Glenn");
All test.as has to do is access the three variables. The problem comes in that 'val' is undefined. The id and name variables however are just fine and return 0000 and Glenn respectively.
package {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.*;
import flash.net.*;
public class test extends MovieClip
{
public function test()
{
super();
//prep request
//EDIT: sorry, I realize now it makes a bit of difference between test.php by itself and http://.../test.php.
var request:URLRequest = new URLRequest("http://somewebsite.com/test.php");
request.method = URLRequestMethod.GET;
var loader:URLLoader = new URLLoader();
//load request
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataLoaded);
loader.load(request);
}
public function dataLoaded(e:Event):void
{
var name = e.target.data.name;
var id = e.target.data.id;
var val = e.target.data.val;
trace("Val: " + val + "ID: " + id + " Name: " + name);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我来说,如何在 Flash IDE 中使用 php 解析器很神秘。在 URLRequest 中使用 http:// 链接。为什么不直接使用由 php 动态构建的 xml。它更具可读性。或者您使用 swfobject 和 flash vars。那么你只需要把它们插入到 javascript 字符串中。
its mysterious to me how you can use a php parser in your flash ide. use a http:// link in your URLRequest. why dont you just use xml that gets build dynamically by php. its so much more readable. or you use swfobject and flash vars. then you just need to insert them in the javascript string.
你可以说我疯了,但是让 php 文件吐出一个 xml feed 供您的 swf 使用不是更简单吗? xml 是 as3 原生的,你甚至不需要解析它,只需加载它就可以了。
call me crazy but wouldnt it be much simpler just to have the php file spit out an xml feed for your swf to consume? xml is native in as3 you dont even have to parse it, just load it and youre good to go.