Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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://ns.adobe.com/flex/mx" 
               xmlns:local="*">

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

</s:Application>
like image 245
Kamo Avatar asked Feb 04 '26 18:02

Kamo


1 Answers

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.

like image 85
JeffryHouser Avatar answered Feb 09 '26 00:02

JeffryHouser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!