I have a Flex 4 Application and it pops up a TitleWindow using PopUpManager.
In the Application I have a Label component... <s:Label id="myLabel"/>
In the TitleWindow popup I have a var declared... public var popLabel:Label;
When the Application creates the popup it then passes in the reference to the app's label component...
var pop1:NewPopup = NewPopup(PopUpManager.createPopUp(this, NewPopup, true));
pop1.popLabel = myLabel;
In the popup I set the value of the label's text... popLabel.text = "test";
After closing the popup, debug shows me that the value was passed back to Application successfully, myLabel.text has been changed to "test" in the Application.
This is basically the example that comes with Flex for passing data in/out of a popup, except the example uses a combo box, but same thing. Works fine.
Now here's my question...
Instead of creating an mx or spark component in Application, if I create a plain String variable... public var appString:String = "";
then create a matching String var inside the popup TitleWindow... public var popString:String;
pass the app's String into the popup the same way as the Label was... pop1.popString = appString;
set the String to "test" inside the popup... popString = "test";
after I close the popup and I'm back in the main Application, debug shows that appString is ""
Why will a value set in a popup on a passed it component stick so the value is still present in Application's component when the popup closes, but a value set on a passed in String var does not stick and is not present in Application after the popup closes? Is it a pass by ref / pass by value issue? I know I can do a parentApplication.appString = "test" within the popup as a workaround, but I really don't want to hard code the appString variable name in the popup and create a tightly-coupled design. What is a good way to pass a simple String into the popup when the String was created in AS and not mxml?
first time you are passiing a label, a label is an object and so its passed by reference
the second time you are passing a string, string is a primitive and is passed by value
personally I would dispatch a custom event to pass data out of the popup