How to prompt user while in a loop without the code continuing to execute (via a popup window)

125 Views Asked by At

I have a datagrid populated with Objects (representing .pdfs) who all share an "indexed" property (indexed in a SQL table). If they are indexed, their respective checkbox is checked and indexed is set to true. I also have a button in my window, that when clicked, the selected objects are called to be indexed.

The problem is that if some are already indexed, I should prompt the user to decide what to do. Ignore (dont do anything) or Replace (delete in table and re-index). This is what I tried but all it does is stack the windows and continues to index them all.

private function indexPDFData(evt:MouseEvent):void  //button handler
    {
        var i:int=0;

        if(pdfScreen.grid2.selectedIndices.length>0) //if items are selected
        {
                for each(var item:Object in pdfScreen.grid2.selectedItems)
                {
                    if(item.indexed=="true")
                    {
                        var window:CustomPopUp = PopUpManager.createPopUp(pdfScreen, CustomPopUp, true) as CustomPopUp;
                        window.ignoreBtn.addEventListener(MouseEvent.CLICK, ignore);
                        window.replaceBtn.addEventListener(MouseEvent.CLICK, replace);
                    }
                }

            sendNotification(ApplicationFacade.COMMAND_INDEX_PDFS, (pdfScreen.grid2.selectedItems));
            pdfScreen.controlBtns.enabled=false;
        }
        else
        {   
            Alert.show("Must select an issue to index!", "Index PDFs");     
        }
    }

What I would like is the loop to stop while the user makes a choice, and continue after he has clicked on of the two choices inside the popup window. I've tried many approaches but none of them work. I'm pretty new to as3 so any help or insight would really be appreciated!

1

There are 1 best solutions below

2
Pan On
private var currentIndex:int;//used to remember the index of the item whose indexed is true

private function indexPDFData(evt:MouseEvent):void  //button handler
{
    if(pdfScreen.grid2.selectedIndices.length>0) //
    {
         checkItems(0);
    }
    else
    {
         Alert.show("Must select an issue to index!", "Index PDFs");     
    }

}

private function checkItems(startIndex:int):void {

     for (var i:int = startIndex; i < pdfScreen.grid2.selectedItems.length; i++)
     {
          var item:Object = pdfScreen.grid2.selectedItems[i];

          if(item.indexed=="true")
          {
               var window:CustomPopUp = PopUpManager.createPopUp(pdfScreen, CustomPopUp, true) as CustomPopUp;
               window.ignoreBtn.addEventListener(MouseEvent.CLICK, ignore);
               window.replaceBtn.addEventListener(MouseEvent.CLICK, replace);
               currentIndex = i;//call checkItems(currentIndex + 1) when close window
               break;
          }
     }

    sendNotification(ApplicationFacade.COMMAND_INDEX_PDFS, (pdfScreen.grid2.selectedItems));
    pdfScreen.controlBtns.enabled=false;
}

When you close window(Your CustomPopUp), remember to call checkItems(currentIndex + 1);