0 Replies Latest reply on Feb 8, 2011 3:17 AM by _spoboyle

    finding suitable screen position for popups

    _spoboyle Level 4

      I have implemented a toast style popup system for my application and everything seems to work well apart from when I have more than one popup appearing at a time.


      the popup is just a spark window


      I use the following code to position the popup on the screen

      (adapted from http://www.adobe.com/devnet/air/flash/quickstart/articles/creating_toast-style_windows.htm l)


      private function findSpotforPopup(width:Number, height:Number):Point
                  var spot:Point = new Point();
                  var done:Boolean = false;
                  for each(var screen:Screen in Screen.screens)
                      currentScreen = screen;
                      for(var x:int = screen.visibleBounds.x + screen.visibleBounds.width - width - GUTTER; 
                          x >= screen.visibleBounds.x; x -= (width + GUTTER))
                          for(var y:int = screen.visibleBounds.y + screen.visibleBounds.height - height - GUTTER;
                              y >= screen.visibleBounds.y; y -= 10)
                              var testRect:Rectangle = new Rectangle(x, y, width + GUTTER, height + GUTTER);
                                  spot.x = x;
                                  spot.y = y;
                                  done = true;
                  return spot;
              private function isOccupied(testRect:Rectangle):Boolean
                  var occupied:Boolean = false;
                  for each (var window:NativeWindow in NativeApplication.nativeApplication.openedWindows)
                      occupied = occupied || window.bounds.intersects(testRect);
                  } return occupied;


      That all works fine. Here's how I add the popup to the screen.

                      var reminderPopup:ReminderPopup = new ReminderPopup();
                      popups.addItem(reminderPopup); // popups is an array collection of all the popups
                      var position:Point = findSpotforPopup(reminderPopup.width, reminderPopup.height);
                      reminderPopup.visible = true;
                      reminderPopup.nativeWindow.x = position.x;
                      reminderPopup.nativeWindow.y = currentScreen.bounds.height;


      Now you can see that I animate the popup from the bottom of the screen to the desired location. However this means if I add 2 popup at the same time the second popup can be placed where the first one is heading too since it's not there yet.


      Any suggestions of how to solve this?