English 中文(简体)
设计模式,要求在执行方法之前开展多种活动?
原标题:Design Pattern to require multiple events before executing method?

多次发生一些事件后,我需要执行一些法典,我早就提出反响,但我感到必须找到更好的办法。

例如,有5份档案需要装上,然后,一个调查组的构成部分将开始运行。

如果我设立了一个反省,即每当要求提交档案时每增加一次,然后每当一次装满一次,则我冒着风险,即头两个或三个档案可能完全装满,直到我的代码接近要求第四和第五卷,这意味着如果我仍有两个文件要装上,我的反响将是零的,从而使得统一调查部分过早启动。

在有些情况下,你可以知道在请求提出之前需要装满的数量,但第一个档案可能载有档案的途径(因此是数量)。 (这种卷宗载荷情景只是试图解释的I m模式的一个实例。)

是否有人对此采取 solution强的解决办法? (我的描述是否有意义?) 感谢!

问题回答

Before executing a request, store a reference (a unique request uri, the loader object or a special command object) in a list. When a loader has finished, remove that object and call a function that checks if there are remaining active tasks in the list.

提出请求或一般要求并不具体,只能用于需要等待多起行动才能完成的任何事情。 多重清单可用于同时处理多种类型的行动。 清单中储存的物体可作为command Object加以执行,从而可提供更多有关这项任务的信息。 http://en.wikipedia.org/wiki/Command_pattern”rel=“nofollow”

If you re doing just loading, like Jacob, I would also suggest a library that handles loading

If the case of a more complicated situation like mixing loaders and other event listeners, I would suggest using an event that fires whenever there is any change to any of the dependencies. In addition all the objects/classes would have a state.

然后,我将设立一个听众,为需要履行职能或启动职能的那一类人增加职能,这具有3个参数。

  • object with event dispatcher (assuming they all use the same update event) ie. assetLoader
  • name of object state ie. headerLoaded
  • state value s desired ie. true

the function would add the listener to a chain of listeners, and any time any of the listeners fires, all objects would check if the state value.

这样做也会使退步(例如当用户使用一个顿语时,内容开始装货,而用户则取消,即使所有资产装载,一个物体的状态都是假的,从而不允许该项目完成) 如果你使用柜台,那就等于是增加,而不是拉平,但更可靠。

Looking for a design pattern? Try the command pattern (http://johnlindquist.com/2010/09/09/patterncraft-command-pattern/) (The video is a great example of what command pattern is and how it works - using Starcraft as an example.

The implementation is that you queue your load commands so that they do not execute out of order, and you can add the enable or disable commands to your command que. So the command pattern will play back your commands something like: load, load, load, enable ui item, load, load, enable another item

Good luck





相关问题
Flex: Text Input that accepts number only

Need a code that only accepts numbers. Upon inputting, the code must check if it is number, if not, it must remove the entered key or not enter it at all

How to dynamically generate variables in Action Script 2.0

I have a for loop in action script which I m trying to use to dynamically create variable. Example for( i = 0 ; i &lt 3 ; i++) { var MyVar+i = i; } after this for loop runs, i would like to ...

drag file(s) from destop directly to flash webpage

Could someone please let me know if is possible to drag (multiple) files from desktop directly into a flash webpage. If yes could you please link me to some online resources.

Can XMLSocket send more than once in a frame?

I have a XMLSocket and I call send twice in the same function. The first send works but the second does not? Does XMLSocket have a restriction to only send one message per frame? Do I have to queue ...

How do you stop a setInterval function?

I have a function that I want to run at an interval within a frame. I use the following code to start the function: var intervalID = setInterval(intervalFunction, 3000); Then, in a button s ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

热门标签