Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try the following approach:</p> <ul> <li>prevent mouse down event in capture phase </li> <li>Itemclick event occures anyway, so just remember clicked item index and display confirmation dialog</li> <li>In alet's close handler do the actual change if neccessary.</li> </ul> <p>Here's an example:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)" &gt; &lt;mx:Script&gt; &lt;![CDATA[ import mx.controls.Alert; import mx.events.CloseEvent; import mx.events.FlexEvent; import mx.events.ListEvent; [Bindable] private var formDirty:Boolean = false; protected function application1_creationCompleteHandler(event:FlexEvent):void { myList.addEventListener(MouseEvent.MOUSE_DOWN, myList_mouseDownHandler, true); } protected function myList_mouseDownHandler(event:MouseEvent):void { if (formDirty) { event.preventDefault(); event.stopImmediatePropagation(); } } protected function myList_itemClickHandler(event:ListEvent):void { if (formDirty) { var alert:Alert = Alert.show("Save changes?", "Confirm save", Alert.YES | Alert.NO | Alert.CANCEL, null, alertCloseHandler); alert.data = event.rowIndex; } } private function alertCloseHandler(evt:CloseEvent):void { var alert:Alert = evt.target as Alert; switch (evt.detail) { case Alert.YES: //Save changes // // Whatever.... // case Alert.NO: //manually change list index cahnge // we also fall here from Alert.Yes case formDirty = false; myList.selectedIndex = alert.data as int; break; case Alert.CANCEL: //Do notthing: break; } } protected function invalidateButton_clickHandler(event:MouseEvent):void { formDirty = true; } ]]&gt; &lt;/mx:Script&gt; &lt;mx:VBox&gt; &lt;mx:List id="myList" itemClick="myList_itemClickHandler(event)"&gt; &lt;mx:dataProvider&gt; &lt;mx:ArrayCollection&gt; &lt;mx:String&gt;Item 0&lt;/mx:String&gt; &lt;mx:String&gt;Item 1&lt;/mx:String&gt; &lt;mx:String&gt;Item 2&lt;/mx:String&gt; &lt;mx:String&gt;Item 3&lt;/mx:String&gt; &lt;mx:String&gt;Item 4&lt;/mx:String&gt; &lt;/mx:ArrayCollection&gt; &lt;/mx:dataProvider&gt; &lt;/mx:List&gt; &lt;mx:Button id="invalidateButton" click="invalidateButton_clickHandler(event)" label="{formDirty?'Invalidated':'Invalidate form'}" enabled="{formDirty?false:true}"/&gt; &lt;/mx:VBox&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload