Re: Passing a variable from an app to a component
Or you can access the data in the application using
Application.application.myDataVar.
----- components/CustomTitleWindow.as -----
package components
{
import flash.events.Event;
import flash.events.MouseEvent;
import mx.containers.TitleWindow;
import mx.controls.Button;
import mx.controls.Text;
import mx.core.Application;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
public class CustomTitleWindow extends TitleWindow{
public function CustomTitleWindow(){
super();
this.setStyle("horizontalAlign", "center");
this.addEventListener(FlexEvent.CREATION_COMPLETE,
creationCompleteHandler);
this.title = "Info was Passed from Application";
var txt:Text = new Text();
txt.setStyle("fontSize", "12");
txt.setStyle("fontWeight", "bold");
txt.width = 300;
txt.text = Application.application.info;
this.addChild(txt);
var btn:Button = new Button();
btn.label = "Close";
btn.setStyle("fontSize","12");
btn.addEventListener(MouseEvent.CLICK, closeHandler);
this.addChild(btn);
}
private function closeHandler(event:MouseEvent):void{
PopUpManager.removePopUp(this);
}
private function creationCompleteHandler(event:Event):void{
PopUpManager.centerPopUp(this);
}
}
}
----- PopupPassInfo.mxml -----
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import components.CustomTitleWindow;
import mx.managers.PopUpManager;
public var info:String = "This is the information you will need!!!";
private function clickHandler():void{
PopUpManager.createPopUp(this, CustomTitleWindow, true);
}
]]>
</mx:Script>
<mx:Button label="Pass Text to Popup"
fontSize="12" click="clickHandler()"/>
</mx:Application>
|