14 Replies Latest reply on Apr 5, 2008 12:27 PM by ntsiii

    Alert without button

    Starlover_jacob Level 1
      Hi there,

      I have a piece of code that takes a bit of time and i don't know how long..
      so what i want to do is put an alert window on my screen while the code is running..and remove it when my piece of code is done. The user is not allowed to remove the alert window, so my question: How to create an alert window without any buttons on it.

      please some help
      Greets, jacob
        • 1. Re: Alert without button
          Bryan Dresselhaus Level 1
          You can use the PopUpManager class to add and remove a UIComponent.

          Go to http://livedocs.adobe.com/labs/flex3/langref/ then PopUpManager class, addPopUp static method.

          This code would add a popup and not let the user interact with the background. The "this" keyword refers to the Application.

          var tw = new TitleWindow();
          tw.title = "My Title";
          mx.managers.PopUpManager.addPopUp(tw,this,true);
          • 2. Re: Alert without button
            SujitG Level 2
            You can create a custom component, which just displays a message saying wait/loading. In the code below customComponent is your custom component and the renderSuggestionModule() function will add the component as a modal dialog and the closeSuggestion() will remove it. You call the renderSuggestionModule() function before executing the script and call the closeSuggestion() after the code execution is completed. Hope this helps.

            var customComponent:CustomComponent;
            private function renderSuggestionModule(event:ModuleEvent):void
            {
            customComponent = new CustomComponent();
            PopUpManager.addPopUp(customComponent, this, true);
            PopUpManager.centerPopUp(customComponent);
            }

            public function closeSuggestion():void
            {
            PopUpManager.removePopUp(customComponent);
            }
            • 3. Re: Alert without button
              Starlover_jacob Level 1
              Hi,
              First of all thanx for the quick answer!
              The things you suggested worked fine in a project, the only problem is that i am trying to create that popup from a class.. so "this" in the line: var pop2:Canvaspopup = Canvaspopup(PopUpManager.createPopUp(this,Canvaspopup,true));
              is not possible anymore, any suggestions on how to solve this?

              I now got the following errors: (AirGeneralImplementation is the name of my class)
              1067: Implicit coercion of a value of type AirGeneralImplementation to an unrelated type flash.display:DisplayObject.
              • 4. Re: Alert without button
                Starlover_jacob Level 1
                I figured it out.
                This did the trick:

                pop2=new Canvaspopup();
                pop2 = Canvaspopup(PopUpManager.createPopUp(Application.application as Sprite,Canvaspopup,true));
                PopUpManager.centerPopUp(pop2);
                • 5. Re: Alert without button
                  Starlover_jacob Level 1
                  Hey guys,
                  A new problem now..
                  I am using the popup for a piece of code that takes some time to run.. and when its done running i remove the popup. But when i run the script again, my popup doesn't appear. :(

                  Here the code i use:


                  private var pop2:Canvaspopup;
                  public function imageSelected(event:Event):void // i cum here on the select event from a file dialog box.
                  {
                  trace(pop2);
                  if(pop2!=null)
                  pop2=null;
                  pop2=new Canvaspopup();
                  pop2 = Canvaspopup(PopUpManager.createPopUp(Application.application as Sprite,Canvaspopup,true));
                  PopUpManager.centerPopUp(pop2);
                  // here i do some image stuff like use a loader for the selected image
                  }
                  public function handleImageComplete(event:Event):void //when the loader is complete i cum here
                  {
                  // do some image resizing and saving
                  PopUpManager.removePopUp(pop2);
                  pop2=null;

                  }

                  please some help
                  • 6. Re: Alert without button
                    dietmar.paulus Level 1
                    hey

                    in the imagecomplete handler you set pop2 = null

                    so

                    in the image select handler your if is always false so you never will make another popUp;
                    • 7. Re: Alert without button
                      Starlover_jacob Level 1
                      Thanx a lot, you were totally right, it works now.

                      But what i don't understand.. if i use an if statement without {} it always executes only one rule underneath that if right?

                      if(pop2!=null)
                      pop2=null; // will only execute this rule.
                      pop2=new Canvaspopup();


                      if(pop2!=null)
                      {
                      pop2=null;
                      pop2=new Canvaspopup(); // will execute both rules
                      }

                      so what i thought was that when pop2 is empty he just goes on with pop2=new Canvaspopup();
                      • 8. Re: Alert without button
                        dietmar.paulus Level 1
                        Sorry, I didn't see that you haven't used the curly brackets.

                        You are right with that. Really strange???
                        • 9. Re: Alert without button
                          Starlover_jacob Level 1
                          yes indeed strange, but your solution :removing the pop2=null worked fine, i now get a popup each time i execute my code. Don't ask me why, but it works and thats the most important right? :D

                          Greets, jacob
                          • 10. Re: Alert without button
                            Starlover_jacob Level 1
                            hello,
                            Need some help or suggestions again..

                            After going from flex3 beta to flex 3 my problem is back..
                            I'm not sure its cum with the new installation, but the thing is i create a popup.. execute some code like loading,resizing and saving an image and remove the popup (see code examples above)

                            The problem is that my popup not always shows.
                            sometimes it shows like i want, but it could be that the next time it shows nothing, or just a blurred screen without my popup.. Verry weird

                            please some help
                            • 11. Re: Alert without button
                              ntsiii Level 3
                              You don't need to be nulling and newing the popup component at all.

                              You only need to instantiate a component if you are using addPopup(), but not with createPopUp()

                              Take all that out and see if that helps.

                              Tracy

                              • 12. Re: Alert without button
                                Starlover_jacob Level 1
                                Thanx for the answer, but still the same result :(
                                used code:


                                // in the init i declare the var so i can access it in the functions
                                private var myTitleWindow:TitleWindow;

                                //i use a file dialog box to select my image.. if its selected i go into the imageselected function where i create the popup like this:
                                public function imageSelected(event:Event):void
                                {
                                myTitleWindow = new TitleWindow();
                                myTitleWindow.title = "My Window Title";
                                myTitleWindow.width= 220;
                                myTitleWindow.height= 150;
                                PopUpManager.addPopUp(myTitleWindow,Application.application as Sprite, true);
                                PopUpManager.centerPopUp(myTitleWindow);
                                // here i load the image and call functions like resize for thumbnail and save.
                                }

                                // the loading/resizing and saving takes a while.. so if its done i remove the popup like this:
                                public function handleImageComplete():void
                                {
                                PopUpManager.removePopUp(myTitleWindow);
                                }

                                And it still pops up when he likes it..
                                • 13. Re: Alert without button
                                  Starlover_jacob Level 1
                                  Hello everyone,

                                  I solved my problem.
                                  What happened was that he was to busy executing the code that he didn't find time to refresh the screen.
                                  So what i did was i created a timer of 100 milliseconds after creating the popup, so he got time to show the popup on the screen.
                                  After the timer i continue the rest of my code (loading the image and calculating the smaller one)
                                  My code now looks like this:
                                  ------------------------------------------------------
                                  // when image is selected i call the imageselected function
                                  imageFile.addEventListener(Event.SELECT, imageSelected);

                                  public function imageSelected(event:Event):void
                                  {
                                  pop2 = ImageLoadpopup(PopUpManager.createPopUp(Application.application as Sprite,ImageLoadpopup,true));
                                  PopUpManager.centerPopUp(pop2);

                                  var myTimer:Timer = new Timer(100, 1);
                                  myTimer.addEventListener("timer", timerHandler);
                                  myTimer.start();
                                  }
                                  public function timerHandler(event:TimerEvent):void
                                  {
                                  // here i create a new loader and when that's complete i call another function that handles the resize and saving.
                                  }
                                  ------------------------------------------------------

                                  So, the timer forces the code to wait, so it gets enough time to show my popup.

                                  Greets, jacob
                                  • 14. Re: Alert without button
                                    ntsiii Level 3
                                    Ahh. Another solution to this might be to use callLater();
                                    Tracy