ActionScript 3.0 URLRequest with Relative Link

醉酒当歌 提交于 2020-01-16 18:55:21

问题


I am trying to pass some data between PHP and Flash. In Flash I have managed to get the code below working. The problem is I want to use a relative link such as "data/config.php" however this gives me the following error:

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error.

I tried looking up the error but it seems to have many possible causes and I can't figure out a way around it in my case. Here is the code (this works when the url is absolute):

submit_btn.addEventListener(MouseEvent.CLICK, onClickHandler);

function onClickHandler(event:MouseEvent):void
{
    var variables:URLVariables = new URLVariables();
    var url_Loader:URLLoader = new URLLoader;
    var url_Request:URLRequest = new URLRequest("config.php");

    url_Request.method = URLRequestMethod.POST;
    url_Request.data = variables;

    url_Loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    url_Loader.addEventListener(Event.COMPLETE, completeHandler);

    variables.uname = uname_txt.text;
    variables.sendRequest = "parse";
    url_Loader.load(url_Request);
};

function completeHandler(event:Event):void
{
    var phpVar1 = event.target.data.var1;
    var phpVar2 = event.target.data.var2;

    result1_txt.text = phpVar1;
    result2_txt.text = phpVar2;
};

回答1:


You do not give enough information to fix your issue. You have an unhandled event.

Error #2044: Unhandled ioError

So why not listen for that event and figure out the issue.




回答2:


If you're using Flex, one option is to build an absolute path with the help of the FlexGlobals.topLevelApplication object.

You can for example get the URL of the page :

FlexGlobals.topLevelApplication.url


来源:https://stackoverflow.com/questions/16796665/actionscript-3-0-urlrequest-with-relative-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!