博客
关于我
使用Flex中HttpService的应用开发(三)
阅读量:474 次
发布时间:2019-03-06

本文共 1058 字,大约阅读时间需要 3 分钟。

在Flex应用中使用HTTPService组件进行数据交互是一个强大的工具。以下是对该技术的详细优化和应用方法:

1. 数据转换与处理

resultHandler函数中,处理服务器返回的数据:

private function resultHandler(event:ResultEvent, token:AsyncToken):void
{
// 假设myData是一个数组,包含书籍数据
var obj:Contact;
for (var i:int=0; i < myData.length; i++)
{
obj = new Contact(myData.getItemAt(i));
myData.setItemAt(obj, i);
}
}

2. 优化HTTPService使用

getData函数中,优化参数传递:

private function getData():void
{
contactService.url = "data/books.xml";
var responder:ItemResponder = new ItemResponder(resultHandler, faultResultHandler);
var params:Object = { };
params.firstname = "san";
params.lastname = "zhang";
var token:AsyncToken = contactService.send(params);
token.addResponder(responder);
}

3. 动态参数传递

可以直接传递动态对象:

contactService.send({firstname:"san", lastname:"zhang"});

4. 跨域策略配置

确保服务器端配置了crossdomain.xml,允许指定域名访问:

5. 视图层绑定

在MXML中绑定HTTPService结果:

${txtfirstname.text}
${txtlastname.text}

通过以上优化,Flex应用能够高效地与服务器通信,正确处理数据,并在视图层正确显示结果。

转载地址:http://gpmbz.baihongyu.com/

你可能感兴趣的文章
Notepad++在线和离线安装JSON格式化插件
查看>>
notepad++最详情汇总
查看>>
notepad++正则表达式替换字符串详解
查看>>
notepad如何自动对齐_notepad++怎么自动排版
查看>>
Notes on Paul Irish's "Things I learned from the jQuery source" casts
查看>>
Notification 使用详解(很全
查看>>
NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
查看>>
NotImplementedError: Could not run torchvision::nms
查看>>
nova基于ubs机制扩展scheduler-filter
查看>>
Now trying to drop the old temporary tablespace, the session hangs.
查看>>
nowcoder—Beauty of Trees
查看>>
np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
查看>>
np.power的使用
查看>>
NPM 2FA双重认证的设置方法
查看>>
npm build报错Cannot find module ‘html-webpack-plugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack‘解决方法
查看>>
npm C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
查看>>