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

你可能感兴趣的文章
org.apache.ibatis.exceptions.PersistenceException:
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
SQL-CLR 类型映射 (LINQ to SQL)
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>
org.tinygroup.serviceprocessor-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>
org/hibernate/validator/internal/engine
查看>>
Orleans框架------基于Actor模型生成分布式Id
查看>>
SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
查看>>
ORM sqlachemy学习
查看>>
Ormlite数据库
查看>>
orm总结
查看>>