PDA

View Full Version : Passing Parameters


bubba
12-14-2007, 11:28 PM
Hello All ---

I am just learning Flex2, although I am experienced with Flash and AS3. I have what I think is a pretty basic question, but I can not seem to figure it out. My Application file is calling a PopUp Component created with a TitleWindow (SimpleDialogue). I have a button in the Application that when it's clicked will open the PopUpComponent. How can I pass a variable/parameter from the Application to the TitleWindow for the text. Here's the code I am using in Application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1055" height="826">
<mx:Script>
<![CDATA[

import dialogue.SimpleDialogue;
import mx.managers.PopUpManager
import mx.containers.TitleWindow;

private var myPopUp:TitleWindow

private function showPopUp():void

myPopUp = PopUpManager.createPopUp(this,dialogue.SimpleDialo gue,true) as TitleWindow;
PopUpManager.centerPopUp(myPopUp)
}
]]>
</mx:Script>

<mx:Button label="Show Popup Dialogue" click="showPopUp()"></mx:Button>
</mx:Application>


Here's the (basic) code in the SimpleDialogue Class:


<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" title="My First Dialogue Box" >
<mx:Label id="message" text="" fontSize="24">

</mx:Label>

</mx:TitleWindow>


I know this is got to be very basic, but I think I am just too new at Flex.

Thanks for any and all replies.

geeta219
12-17-2007, 05:29 AM
Hi

in your main application file u need to create object of ur simpleDilogue class.


private var myPopUp:SimpleDialogue

private function showPopUp():void{

myPopUp = PopUpManager.createPopUp(this,dialogue.SimpleDialo gue,true) as SimpleDialogue

myPopUp.message.text="hello"
}


like this you can access objects and properties of your dilogue class and also can wite listeners for them.

Thanks,

dr_zeus
12-17-2007, 08:59 PM
The method geeta mentioned will work fine. All subcomponents in an MXML component are publicly accessibly by default.

However, if I were to build this application, I would expose a separate text property to encapsulate the design of SimpleDialogue.

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" title="My First Dialogue Box" >
<mx:Label id="message" text="{this.text}" fontSize="24"/>
<mx:Script>
private var _text:String = "";

[Bindable]
public function get text():String
{
return this._text;
}

public function set text(value:String):void
{
this._text = value;
}
</mx:Script>
</mx:TitleWindow>

bubba
12-17-2007, 10:02 PM
Thank you both for the response.

dr_zeus: As I am new to Flex, I am assuming that this getter/setter would be available to me in the application file? At which point I could set the text (in application) and it would automatically be updated (in SimpleDialogue) as it is bound to these getter/setter functions?

Thanks.

dr_zeus
12-18-2007, 06:00 PM
Yes, the text property I created is public, and it can be accessed like any public variable or property.

mySimpleDialogue.text = "whatever";