Flex - ResizeEvent.RESIZE 的问题 [英] Flex - Problem with ResizeEvent.RESIZE

查看:18
本文介绍了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

推荐答案

而不是对 ResizeEvent 做出反应,ResizeEvent 将在调整大小期间触发每一帧(即,如果您点击最大化"并且组件从 widh 重绘需要 3 帧/eight = 0 to width/height = MaxValue) 然后 resize 事件将触发 3 次,您可以观察"宽度和高度的属性.

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.

var widthWatch:ChangeWatcher = ChangeWatcher.watch(this, 'widht', resizeHandler)
var heightWatch:ChangeWatcher = ChangeWatcher.watch(this, 'height' resizeHandler)

这实际上将监视属性,类似于数据绑定,并在宽度或高度发生变化时执行您的 resizeHandler.如果宽度和高度同时变化,这有一个小缺点,即两次触发处理程序,但这可以通过执行工作的第三个函数来解决,如果它不是预定要调用的,则由您的处理程序调用.代码:

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:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onCreationComplete(event)">
<mx:Script>
 <![CDATA[
  import mx.binding.utils.ChangeWatcher;

  private var widthWatch:ChangeWatcher;
  private var heightWatch:ChangeWatcher;
  private var resizeExecuting:Boolean = false;

  private function onCreationComplete(event:Event):void
  {
   widthWatch = ChangeWatcher.watch(this,'width',onSizeChange);
   heightWatch = ChangeWatcher.watch(this,'height',onSizeChange);
  }

  private function onSizeChange(event:Event):void
  {
   if(!resizeExecuting)
    callLater(handleResize);
   resizeExecuting = true;
  }

  private function handleResize():void
  {
   //do expensive work here
   resizeExecuting = false;
  }

  private function stopWatching()
  {
   //invoke this to stop watching the properties and prevent the handleResize method from executing
   widthWatch.unwatch();
   heightWatch.unwatch();
  }

 ]]>
</mx:Script>
</mx:Application>

我更喜欢 change watcher 方法,因为它会在 width 和 height 属性更改后触发,这与在 width 和 height 属性正确更新之前触发的 resize 事件不同.

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.

这篇关于Flex - ResizeEvent.RESIZE 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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