结合的URLRequest,URLLoader和完整的事件监听器在ActionScript 3.0? [英] Combining URLRequest, URLLoader and Complete Event Listener In Actionscript 3.0?

查看:128
本文介绍了结合的URLRequest,URLLoader和完整的事件监听器在ActionScript 3.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理数据时,我总是要编写如下:

  VAR dataSourceRequest:的URLRequest =新的URLRequest(/路径/ file.xml);
VAR dataSourceLoader:的URLLoader =新的URLLoader(dataSourceRequest);
dataSourceLoader.addEventListener(引发Event.COMPLETE,handleDataSource);
 

虽然我能理解这两个对象的有用性和事件监听器是分开的,因为他们经常互相合作。我想知道是否有将它们组合所有的方法?最接近我能得到的是这样的,但它是一个有点无意义/嵌套:

  VAR dataSourceLoader:的URLLoader =新的URLLoader(新的URLRequest(/路径/ file.xml));
dataSourceLoader.addEventListener(引发Event.COMPLETE,handleDataSource);
 

我真正的爱情是什么,可以自动结合的URLRequest,URLLoader和完成的事件监听器是这样的:

  VAR数据源:无论=新的不管(/路径/ file.xml,handleDataSource);
 

解决方案

没有......这是一个架构决策的土坯制成,一个好的那个。两两班做的非常不同的工作,做这些工作做好。事件侦听器可以处理整个事件多次,所以很多比在这种情况下回调更灵活。

您可以但是创建一个包装的所有功能,并在完全相同的方式工作,你想要它!一个班

when handling data, i always have to write the following:

var dataSourceRequest:URLRequest = new URLRequest("/path/file.xml");
var dataSourceLoader:URLLoader = new URLLoader(dataSourceRequest);
dataSourceLoader.addEventListener(Event.COMPLETE, handleDataSource);

while i can understand the usefulness of these 2 objects and event listener being separate, since they often work with each other i'd like to know if there is a method that will combine them all? the closest i can get is this, but it's a bit pointless/nesting:

var dataSourceLoader:URLLoader = new URLLoader(new URLRequest("/path/file.xml"));
dataSourceLoader.addEventListener(Event.COMPLETE, handleDataSource);

what i'd really love would be something that automatically combines the URLRequest, URLLoader and completed event listener like this:

var dataSource:Whatever = new Whatever("/path/file.xml", handleDataSource);

解决方案

No... it's an architectural decision that adobe made and a good one at that. Two two classes do very different jobs and do those jobs well. The event listener allows you to handle the complete event multiple times and so is a lot more flexible than a callback in this instance.

You could however create a class that wraps all that functionality and works in exactly the way you want it to!

这篇关于结合的URLRequest,URLLoader和完整的事件监听器在ActionScript 3.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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