Actionscript 3 如何使用此URL请求脚本?

Actionscript 3 如何使用此URL请求脚本?,actionscript-3,flash,Actionscript 3,Flash,我在一周前开始学习ActionScript3,并偶然发现了一条巨大的学习曲线。我在互联网上找到了这个脚本: var _loader:URLLoader; var _request:URLRequest; function loadData():void { _loader = new URLLoader(); _request = new URLRequest("http://www.travoid.com/game/Purchase.php?gid=1"); _req

我在一周前开始学习ActionScript3,并偶然发现了一条巨大的学习曲线。我在互联网上找到了这个脚本:

var _loader:URLLoader;
var _request:URLRequest;

function loadData():void {
    _loader = new URLLoader();
    _request = new URLRequest("http://www.travoid.com/game/Purchase.php?gid=1");
    _request.method = URLRequestMethod.POST;
    _loader.addEventListener(Event.COMPLETE, onLoadData);
    _loader.addEventListener(IOErrorEvent.IO_ERROR, onDataFailedToLoad);
    _loader.addEventListener(IOErrorEvent.NETWORK_ERROR, onDataFailedToLoad);
    _loader.addEventListener(IOErrorEvent.VERIFY_ERROR, onDataFailedToLoad);
    _loader.addEventListener(IOErrorEvent.DISK_ERROR, onDataFailedToLoad);
    _loader.load(_request);
}
function onLoadData(e:Event):void {
    trace("onLoadData",e.target.data);
}
function onDataFailedToLoad(e:IOErrorEvent):void {
    trace("onDataFailedToLoad:",e.text);
}
这一切似乎都是可行的,并且没有产生任何错误或输出,但是当我使用代码的下一部分(我制作的)时,我的问题就出现了

我得到这个错误:

ReferenceError:错误#1069:在上找不到属性数据 flash.display.SimpleButton,没有默认值。在 travoid_fla::Main Timeline/vpBuy()onLoadData

这可能是因为:

if (e.target.data == "false") {
我希望
e.target.data
是存储在网页上的值(显示为false),但显然不是。根据我在互联网上找到的代码,是什么存储了网页上的信息

谢谢,
Ethan Webster。

URLLoader加载方法是异步的,您必须在triyng获得结果之前等待服务器响应

onLoadData和onDataFailedToLoad函数就是用来实现这一点的。收到响应后,调用onLoadData函数,您可以在e.target.data或_loader.data中获取数据

函数vpBuy中的错误是您试图访问触发MouseEvent(可能是按钮)的对象上的数据属性,而该对象没有此类变量

请尝试以下操作:

/** button clicked load the datas from the server **/
function vpBuy(e:MouseEvent):void
{
    // load the datas from the server
    loadData();
}

/** the datas are well loaded i can access them **/
function onLoadData(e:Event):void 
{
    trace("onLoadData",e.target.data);
    if( e.target.data == "false" ) 
    {
        inf_a.visible = true;
        inf_b.visible = true;
        inf_c.visible = true;
        inf_d.visible = true;
        btn_ok.visible = true;
    }
}

希望这能帮助您:)

有人能帮我吗?可能是重复的
/** button clicked load the datas from the server **/
function vpBuy(e:MouseEvent):void
{
    // load the datas from the server
    loadData();
}

/** the datas are well loaded i can access them **/
function onLoadData(e:Event):void 
{
    trace("onLoadData",e.target.data);
    if( e.target.data == "false" ) 
    {
        inf_a.visible = true;
        inf_b.visible = true;
        inf_c.visible = true;
        inf_d.visible = true;
        btn_ok.visible = true;
    }
}