博客
关于我
使用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/

你可能感兴趣的文章
npm学习(十一)之package-lock.json
查看>>
npm安装 出现 npm ERR! code ETIMEDOUT npm ERR! syscall connect npm ERR! errno ETIMEDOUT npm ERR! 解决方法
查看>>
npm安装crypto-js 如何安装crypto-js, python爬虫安装加解密插件 找不到模块crypto-js python报错解决丢失crypto-js模块
查看>>
npm安装教程
查看>>
npm报错Cannot find module ‘webpack‘ Require stack
查看>>
npm报错Failed at the node-sass@4.14.1 postinstall script
查看>>
npm报错fatal: Could not read from remote repository
查看>>
npm报错File to import not found or unreadable: @/assets/styles/global.scss.
查看>>
npm报错TypeError: this.getOptions is not a function
查看>>
npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
查看>>
npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
查看>>
npm版本过高问题
查看>>
npm的“--force“和“--legacy-peer-deps“参数
查看>>
npm的安装和更新---npm工作笔记002
查看>>
npm的常用操作---npm工作笔记003
查看>>
npm的常用配置项---npm工作笔记004
查看>>
npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
查看>>
npm编译报错You may need an additional loader to handle the result of these loaders
查看>>
npm设置淘宝镜像、升级等
查看>>
npm设置源地址,npm官方地址
查看>>