flex - How to set a public var in a popup window? -
i trying set variable in titlewindow pupup , use in script section. variable not being set , don't know why.
here main.mxml file:
<?xml version="1.0" encoding="utf-8"?> <s:application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minwidth="955" minheight="600" creationcomplete="application1_creationcompletehandler(event)"> <fx:script> <![cdata[ import mx.events.flexevent; import mx.managers.popupmanager; protected function application1_creationcompletehandler(event:flexevent):void { var test:testwindow = testwindow(popupmanager.createpopup(this,testwindow,true)); popupmanager.centerpopup(test); test.testtext = 'test 2'; test.bol = true; } ]]> </fx:script> <fx:declarations> <!-- place non-visual elements (e.g., services, value objects) here --> </fx:declarations> </s:application>
here titlewindow file:
<?xml version="1.0" encoding="utf-8"?> <s:titlewindow 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" close="popupmanager.removepopup(this);" creationcomplete="titlewindow1_creationcompletehandler(event)"> <fx:script> <![cdata[ import mx.events.flexevent; import mx.managers.popupmanager; [bindable] public var testtext:string = 'test 1'; public var bol:boolean = false; protected function titlewindow1_creationcompletehandler(event:flexevent):void { if(bol){ trace('boolean true'); } } ]]> </fx:script> <fx:declarations> <!-- place non-visual elements (e.g., services, value objects) here --> </fx:declarations> <s:label text='{testtext}'/> </s:titlewindow>
the problem label change 'test 1' 'test 2' bol variable not set, why that?
the creationcomplete
event fires when titlewindow has been created , fires once (see component lifecycle).
in case happens in main.mxml file when add pop popupmanager.centerpopup(test);
. bol
getting updated, you're not seeing trace statement because creationcomplete
event has fired.
if want to change value bol
current setup you'll need prior opening pop up.
in general feel better way of doing using getters , setters , data binding (or flex's invalidation methods described in first link).
note: these links provided flex 3 far know holds true in flex 4.
Comments
Post a Comment