0

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 Answers1

0
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);

Pan
  • 2,101
  • 3
  • 13
  • 17
  • That's awesome! It almost worked except for when the break is called, it would immediately go to the indexing (even with the popup). But it lead me in the right direction and it works :D. I added an if statement before the loop to check if the currentIndex is at the end. If it is THEN it starts the indexing process. I really appreciate it! – user1819615 Jun 20 '13 at 15:44
  • Should replace break with return. :) – Pan Jun 20 '13 at 16:09