Flex - ResizeEvent.RESIZE 问题
我的调整大小事件遇到了一个小问题...我自己创建了一个组件,并且该组件在每个调整大小事件中都运行一个复杂的方法。问题是:当我最大化或恢复窗口时,该事件在短时间内被多次调用,没有让我的方法有足够的时间在另一个方法开始之前完全运行...我想知道如果无论如何只能在每次调整大小运动结束时运行此方法。 谢谢
I'm having a little problem with my resize event... I created a component myself, and this component, at each resize event, runs a complex method. Here is the problem: When I maximize or restore my window, this event is called several times in a real short period of time, not letting enough time to my method to run completely before another one starts... I'd like to know if there is anyway of only run this method in the end of each resize movement.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不是对 ResizeEvent 做出反应,ResizeEvent 会在调整大小期间触发每一帧(即,如果您点击最大化并且组件需要 3 帧才能从 widh/ehight = 0 重绘到 width/height = MaxValue),则将触发调整大小事件三次,您可以“观察”宽度和高度的属性。
实际上,这将监视属性,类似于数据绑定,并在宽度或高度发生变化时执行 resizeHandler。这有一个小小的缺点,如果宽度和高度同时改变,则触发处理程序两次,但这可以通过执行该工作的第三个函数来解决,如果不安排调用该函数,则该函数将由处理程序调用。代码:
我更喜欢更改观察程序方法,因为它在宽度和高度属性更改后触发,这与在宽度和高度属性正确更新之前触发的调整大小事件不同。
Instead of reacting to a ResizeEvent, which will fire every frame during a resize (i.e. if you hit maximize and it takes 3 frames for the component to redraw from widh/ehight = 0 to width/height = MaxValue) then the resize event will fire three times, you could 'watch' the properties of width and height.
this will, in effect, watch the properties, similar to data binding, and execute your resizeHandler whenever the width or height change. This has a slight drawback as to firing your handler twice if width and height change at the same time, but that can be solved with a third function that does the work, which gets invoked by your handlers if it isn't schedule to be invoked. The code:
I prefer the change watcher method because it fires after the width and height properties have changed, unlike a resize event wich fires before the width and height properties are correclty updated.
您需要将调整大小事件合并为单个事件。 David Coletta 在此演示文稿中简要讨论了事件合并,但我不记得他是否描述了他是如何做到的。
您可以通过多种方式来完成此操作,我将在下面的伪代码中布局其中一种:
You'll want to coalesce the resize events into a single event. David Coletta talked briefly about event coalescing in this presentation, but I don't remember if he described how he did it.
You could do this in a number of ways, one of which I'll layout in pseudo code below:
在我看来,您正在事件处理程序中执行某些操作,导致触发新的 ResizeEvent.RESIZE 。由于 ActionScript 在单个线程中运行,因此在处理程序运行时没有独立的源可以调度该事件,除非您以某种方式触发它。
It sounds to me like you're doing something in your event handler that is causing a new ResizeEvent.RESIZE to be fired. Since ActionScript runs in a single thread, no independent source could possibly dispatch that event while your handler is running unless you somehow trigger it.
我想指出的是,flex 具有完整的组件生命周期,这可能会帮助您:
尝试一下:
您可以在此处阅读有关 Flex3 组件生命周期的更多信息:
http://www.dlgsoftware.com/primers/Primer_on_Flex3_Component_Lifecycle.htm
I would like to point out that flex has a complete Component lifecycle which might help you:
Try this:
You can read more about the Flex3 Component lifecycle here:
http://www.dlgsoftware.com/primers/Primer_on_Flex3_Component_Lifecycle.htm