动作3 - 我如何使用在此URLRequest脚本? [英] actionscript 3 - How do I use this URLRequest script?

查看:132
本文介绍了动作3 - 我如何使用在此URLRequest脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始学习ActionScript 3的一个星期前,在巨大的学习曲线都有所涉猎。我在互联网上找到此脚本:

  VAR _loader:的URLLoader;
VAR _request:的URLRequest;

功能loadData():无效{
    _loader =新的URLLoader();
    _request =新的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);
}
功能onLoadData(五:事件):无效{
    跟踪(onLoadData,e.target.data);
}
功能onDataFailedToLoad(E:IOErrorEvent):无效{
    跟踪(onDataFailedToLoad:e.text);
}
 

这一切似乎工作,并且不产生错误或输出,但是我的问题来约,当我用code这下部分(我做)

 函数vpBuy(E:的MouseEvent):无效{
    loadData();
    如果(e.target.data ==假){
        inf_a.visible = TRUE;
        inf_b.visible = TRUE;
        inf_c.visible = TRUE;
        inf_d.visible = TRUE;
        btn_ok.visible = TRUE;
    }
}
 

我得到这个错误:

  

的ReferenceError:错误#1069:房产数据未找到   flash.display.SimpleButton并没有默认值。在   travoid_fla :: MainTimeline / vpBuy()onLoadData

这可能是引发此的部分是:

 如果(e.target.data ==假){
 

我希望 e.target.data 什么是存储在Web页面上的值(显示为假),但显然不是。随着code,我发现在互联网上,哪些店网页上的信息?

谢谢,伊桑·韦伯斯特。

解决方案

这是试图它的加载之前检查数据。因为数据加载是一个基于时间的过程,而不是瞬间。所以,你已经让你的数据检查条件等待数据真的装载

我认为你应该使用一个回调函数vpBuy从onLoadData

或者你可以尝试将您的数据查询条件为onLoadData功能,像

 函数onLoadData(五:事件):无效{
    跟踪(onLoadData,e.target.data);
    如果(e.target.data ==假)
    {
            inf_a.visible = TRUE;
            inf_b.visible = TRUE;
            inf_c.visible = TRUE;
            inf_d.visible = TRUE;
            btn_ok.visible = TRUE;
    }
}
 

I started learning ActionScript 3 a week ago and have stumbled across a huge learning curve. I found this script on the internet:

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);
}

This all seems to work and is generating no errors or output, however my issue comes about when I use this next part of code (which I made)

function vpBuy(e:MouseEvent):void{
    loadData();
    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;
    }
}

I get this error:

ReferenceError: Error #1069: Property data not found on flash.display.SimpleButton and there is no default value. at travoid_fla::MainTimeline/vpBuy() onLoadData

The part that is probably throwing this is:

if (e.target.data == "false") {

I was hoping e.target.data was what stored the value on the web page (which displays as false) but apparently not. With the code I found on the internet, what stores the information on the web page?

Thanks, Ethan Webster.

解决方案

that's trying to check data before it's loaded. because data loading is a time based process, not instant. so, you've to make your data check condition wait for data really load

i think you should use a callback function for vpBuy from "onLoadData"

or you can try moving your data check conditional into onLoadData function like

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;
    }
}

这篇关于动作3 - 我如何使用在此URLRequest脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆