5 Replies Latest reply on Aug 18, 2010 9:11 AM by Subeesh Arakkan

    Pass Variable from Main.mxml to Pop.mxml

    djh88ukwb

      Hello All.

       

      I have a project that has two files.

      Main.mxml and Pop.mxml

       

      Main.mxml is obv my main application and it has a variable that contains the link to an image.  This variable changes on a regular basis.

       

      The Pop.mxml file is a TitleWindow that i want to display the image, but on a larger scale.

       

      The code for my Pop.mxml is as:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
                      layout="vertical"
                      title="Tazio AudioCast"
                      showCloseButton="true"
                      width="1022"
                      height="800"
                      close="titleWindow_close(event);" move="doMove(event)">
         
          <mx:Script>
              <![CDATA[
                  import mx.events.CloseEvent;
                  import mx.managers.PopUpManager;
                  import mx.core.Application;
                 
                  [Bindable] public var test:String;
                 
                  private function titleWindow_close(evt:CloseEvent):void {
                      PopUpManager.removePopUp(this);
                  }
                  private function doMove(event:Event):void
                  {//keeps TW inside layout
                      var appW:Number=Application.application.width;
                      var appH:Number=Application.application.height;
                      if(this.x+this.width>appW)
                      {
                          this.x=appW-this.width;
                      }
                      if(this.x<0)
                      {
                          this.x=0;
                      }
                      if(this.y+this.height>appH)
                      {
                          this.y=appH-this.height;
                      }
                      if(this.y<0)
                      {
                          this.y=0;
                      }
                  }
              ]]>
          </mx:Script>
          <mx:SWFLoader width="100%" height="100%" source="swf/slide1.swf"/>
          <mx:Label text="{test}" color="#C00D0D" x="1200"  top="20"/>
         
      </mx:TitleWindow>

       

      What i am struggling with thou, is how do i pass the variable from Main.mxml to Pop.mxml.

       

      I know how to do this with components, its easy enough, but i cant see to do it between these two files.

       

      The vairable i am rying to pass at the momnet is called  "test".

       

      Any help would be great, thanks !

        • 1. Re: Pass Variable from Main.mxml to Pop.mxml
          Subeesh Arakkan Level 4

          Hi,

           

          how are you launching the popup, If you are using PopupManager, try this

           

          var popup:Pop = Pop(PopUpManager.createPopUp(this, Pop, true));
          popup.test = "your value";
          PopUpManager.centerPopUp(popup);
          

          • 2. Re: Pass Variable from Main.mxml to Pop.mxml
            djh88ukwb Level 1

            Thank you very much, that was just what  i needed

             

            One last question, when using the popup manager, is there a way to disable the grey fade that it puts over the whole app ?

            • 3. Re: Pass Variable from Main.mxml to Pop.mxml
              Subeesh Arakkan Level 4

              Yes,

               

              That grey fade is the modal transparency color. If you want you can make your popup non -modal. Just set the modal flag to false, like this

               

              PopUpManager.addPopUp(titleWin,this,false);
              

               

              Or if you want more control over modal color, alpha and duration, check the following blog post

               

              http://mprami.wordpress.com/2008/04/22/alert_popup_modal_transparancy_color_blur_changes/

              • 4. Re: Pass Variable from Main.mxml to Pop.mxml
                djh88ukwb Level 1

                Again thankyou very much, this has solved my problem.

                 

                The one last snag that i have is the following, im not sure if you would be able to help ?

                 

                The variable that i am passing into the popupmodule file is called imgSRC.

                 

                This variable is updated every second, using a function that is linked to a timer.  So the contents of this variable changes often.

                 

                Now when i pass my variable into the popupManager, it takes the value that is in the variable at that time, however when imgSRC changes it doesnt update.

                 

                Is there anyway around this ?

                 

                Here is my PopUpManager function.

                 

                            private function launchFullScreen():void {
                                var win:FullScreen = PopUpManager.createPopUp(this, FullScreen, false) as FullScreen;
                                win.Image = imgSRC;
                                PopUpManager.centerPopUp(win);
                            }

                 

                So ideally i need the win.Image = imgSRC; to run all the time.

                 

                I cant run the overall function all the time, because if the user dosent want the window open, they wont be able to close it.

                 

                Any help would be great !

                • 5. Re: Pass Variable from Main.mxml to Pop.mxml
                  Subeesh Arakkan Level 4

                  Hi,

                   

                  Create your popup instance outside the function so that it can be accessed anywhere from the page.

                   

                  private var win:FullScreen;    
                  private function launchFullScreen():void {
                                  win = PopUpManager.createPopUp(this, FullScreen, false) as FullScreen;
                                  win.Image = imgSRC;
                                  PopUpManager.centerPopUp(win);
                  }
                  

                   

                  Then in the timer event handler, set the image source.

                   

                  if(win)
                        win.Image = imgSRC;