3 Replies Latest reply on Feb 24, 2010 10:02 AM by Flex harUI

    can you access variables in the parent window of a popup?

    cyber0897 Level 1

      hey guys... i basically have a component where i have a button, and on click of that button i have a popup commin up...

      is there a way i can access variables in component?

       

       

      the code i have is:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
                 xmlns:s="library://ns.adobe.com/flex/spark" 
                 xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" initialize="init();">
           ....
           .....
           ......
           <fx:Script source="storyEditorScript.as" />
      
       <s:Button label="Associated Images" click="displayAllImages()" />
       <s:Button label="Associated Videos" />
      
           ...
           ....
           .....     
           
      </s:Group>
      
      

       

      on click of associated images i have a popup commin up... the code i have for that is

       

      public function displayAllImages():void{
           ttlWin = new TitleWindow();
           ttlWin = PopUpManager.createPopUp(this, imageDataPopup, true) as TitleWindow;
      
      //     PopUpManager.centerPopUp(ttlWin);
      }
      

       

       

      when i click the button i need the titlewindow to be able to get variables from the storyEditorScript.as

       


      i've tried doing outerDocument, and parentApplication and all that.. but with no avail...

       

      any help is greatly appretiated!!

       

      oh and for some reason the centerPopup is giving me errors aswell...

       

      any ideas??

        • 1. Re: can you access variables in the parent window of a popup?
          Gregory Lafrance Level 6

          Do center popup in the popup itself, passing "this" as the parameter, and use custom events to pass data to and from popups:

           

          http://cookbooks.adobe.com/post_Very_simple_example_of_using_custom_events_to_pass-15466.h tml

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

          • 2. Re: can you access variables in the parent window of a popup?
            cyber0897 Level 1

            interesting... so basically i would create custom packages and events, and use them to import and export data?

             

            one of the solutions i found was to just use the titlewindow as an array of elements and assign my data to those elements like

             

             

            videoTtlWin = new videoDataPopup();
            videoTtlWin = PopUpManager.createPopUp(this, videoDataPopup, true) as videoDataPopup;
            videoTtlWin["allVideos"].dataProvider = displayAllVideoData;
            videoTtlWin["appliedVideos"].dataProvider = appliedVideoData;
            videoTtlWin["moveToApplied"].addEventListener(MouseEvent.MOUSE_DOWN, moveToAppliedVideos);
            

             

            im not sure if this is good programming practice tho.... probablly has a lot of security drawbacks.. yes?

            • 3. Re: can you access variables in the parent window of a popup?
              Flex harUI Adobe Employee

              If you have a model-view or MVC architecture, the popup would access the

              data model and you wouldn't need code that assumes the set of properties on

              the popup.  However, if you do want to make such an assumption, there should

              be no reason to use ["allVideos"] if you've typed the videoTtlWin as

              videoDataPopup, you should just be able to use videoTtlWin.allVideos.

               

              Which way to go is more or less up to you and where you want to have

              abstractions.

               

              When the popup is "done" it should probably dispatch a custom event

              containing useful information otherwise the code has to assume something

              about the set of properties in the popup again.  But again, it is the same

              trade off.  You'll spend more time creating those abstractions but then it

              will be easier to swap things for different implementations later.  If you

              don't need that or don't have time, then make assumptions about the

              properties and you should be fine.