AS3 How to determine the sequence of events

I am using flex-4-tree (https://github.com/wasbridge/flex-4-tree) in a mobile phone AIR app.

The Tree CLass:

public class Tree extends List
{
    ...
    dataSource.addEventListener(TreeEvent.NODE_EXPANDED, nodeExpandedHandler);
    dataSource.addEventListener(TreeEvent.NODE_COLLAPSED, nodeCollapsedHandler);
    ...
}

There is a menu on the main screen of the app. If the user selects a menu-item, the appropriate action is taken, but if the user expands/collapses a menu-item by selecting the expander icon, the menu-item is expanded/collapsed.

Currently the List change Event is received before the flex-4-tree Expand/Collapse Events.

I need to receive the flex-4-tree Expand/Collapse Events before the List change Event.

Any help would be greatly appreciated.

Answers


Set up a timer in your handler for the ListChangeEvent that defers any action for a tenth of a second. Then if you expand/contract event comes in before the timer ends, you can cancel the action for the change event. Something like this:

private var _expandEventOccurred:Boolean = false;

private function handleListChange(evt:Event):void {

    var timer:Timer = new Timer(100,1);  //100ms = 0.1s
    timer.addEventListener(TimerEvent.TIMER_COMPLETE, handleListChangeTimerEvent);
    timer.start();

}

private function handleExpandContract(evt:Event):void {

    _expandEventOccured = true;

    //perform whatever other actions you need for the expand/contract event

}

private function handleListChangeTimerEvent(evt:Event):void {

    if(_expandEventOccured) {
        _expandEventOccured = false;
        return;
    }

    _expandEventOccured = false;  //needed here as well

    //perform whatever other actions you need for the list change event 

}

Not the cleanest thing in the world, but should do the trick. Hope that helps!


Need Your Help

Encrypted data in URLs

php codeigniter mcrypt

I am developing a PHP application to manage orders for a company. To view an order the URL is currently /orders/view/3502.

Service anniversaries today with SharePoint using calculated fields and filters

date sharepoint filter

I need to create a view that show employees that have their Service anniversary today.