2 Replies Latest reply on Oct 25, 2007 2:48 PM by Julio Carneiro

    how to open a Popup from an AS3 class

    Julio Carneiro
      I have an AS3 standalone class (does not inherit from any other class).

      I want to show a popup window from inside that class using PopupManager addPopup (or createPopup). Problem is that both methods require an iFlexDisplayObject class to indicate where to append the popup to.

      Is there any static property/function that would give me my application object (any display object on the stage will do).

      Something like Application.application would be perfect, but unfortunately Application.application is not available for that class (at least not with 2.0.1).

      I've browsed thru all classes but could not find anything to help.

      For now I'm passing (this or Application.application) as an argument to the class constructor so it can be used later to instantiate the Popup.

      Any help or pointer is mostly appreciated.
      TIA
      julio
        • 1. Re: how to open a Popup from an AS3 class
          Karl_Sigiscar_1971 Level 3

          Here is what we did in our application so we can display a dialog box centered to the Application from anywhere.

          1. Create a map object in the model with a getter/setter for it:

          private var _map:Object = new Object();

          // Map -------------------------------------------------------------

          public function get map() : Object
          {
          return this._map;
          }

          public function set map(value : Object) : void
          {
          this._map = value;
          }

          2. Add the reference of the Application to the map in the creationComplete handler:
          this.model.map["app"] = this;

          3. Pass the reference to the app from the map object when displaying the popup from any class in the application:
          PopUpManager.createPopUp(this.model.map["app"], DialogBoxClass, true));
          • 2. Re: how to open a Popup from an AS3 class
            Julio Carneiro Level 1
            Thanks for the reply, but I found a fix to my problem.

            I was trying to use this construct:
            var app:Application = Application.application;
            PopUpManager.addPopUp(mypop,app);

            That caused a runtime error as for some reason 'app' was not being set, it was always null.

            Then someone suggested I qualified the assignment. I changed it to the following and now it works as expected:
            var app:Application = Application.application as Application;
            PopUpManager.addPopUp(mypop,app);

            go figure, at least I now have a way to access the top application from anywhere.

            hth
            julio