开发者

Auto-detect position changes

I have a custom component Comp that gets its position changed as a result of interactions with other components, etc. I check for changes in its position by constantly checking its position at fixed intervals. I'm looking for a better solution (maybe an event-based solution) to monitor its position so I don't have to check constantly myself.

The 2 possibilities are

  • the component itself is self-aware of its position on stage and reports to the main application (via an event) when it knows that its position changed. Is that possible? Are components self-aware of their position or changes to their position? and what event could I piggyback on when that happens?

  • the other option is that the main application can monitor the position of the component and takes action when that position changes. Is that possible? Can the main application detect changes in the position of its components, and again what event could possibly be used here?

If not, how could I detect when that component changes position without having to constantly check for it myself.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://开发者_如何学Gons.adobe.com/flex/mx" 
               xmlns:local="*">

    <local:Comp id="comp" x="100" y="100" />

</s:Application>


I second the early suggestion to listen to the move event

http://livedocs.adobe.com/flex/3/langref/mx/core/UIComponent.html#event:move

If you want to be more specific, the x and y values will dispatch changed events. So you could also listen to xChanged or yChanged if you wantd to perform different actions on the x or y movement.


Have you tried to listen to the move event?


Maybe you can play with data binding. The BindingUtils interface allows you to set a function on when a watched property is changing: http://livedocs.adobe.com/flex/3/langref/mx/binding/utils/BindingUtils.html#bindSetter()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜