|
Mailing Lists
|
Home /
Groups /
Adobe Flex
passing a variable value from a component to the main application
> hi , I have a flex application with one component . in that component I have defined a variable named "correctUsername" . after I click a button inDave Watts 11/27/10 10:37 A thanks Dave , I binded the variable of my component to my main application's textInput with this code :mojtaba tabatabaie 11/27/10 02:42 P hi , I have a flex application with one component . in that component I have defined a variable named "correctUsername" . after I click a button in the component I give a value to the correctUsername variable . and I want to have that value in my main application . but seems I can't do it in a way I'm doing it . the code is as below : my component is named "signIn" ------------------------- ..... <!-- signIn component --> <fx:script> public var correctUsername:String; ..... public function submitLogin():void{ correctUsername = "ok"; } ... </fx:script> ..... <s:Button label="myBtn" click="submitLogin()"/> --------------------------- --------------------------- my main application: .... <!-- my main application --> <fx:script> public var testSign:signIn; public funtion btnClick():void{ testSign = new signIn(); testInput.text = testSign.correctUsername; } </fx:script> .... <components:signIn id="myComponent"/> <s:TextInput id="testInput"/> <s:Button label="btn" click="btnClick()"/> ------------------------------------------ ------------------------------------------ anyone knows where the problem is? the thing that has mixed me up is that if I give the value of correctUsername variable in my component outside of any funtions it works fine and my main application shows the value correctly , but if I give it value inside any functions the main application doesn't show the value . I'll be appreciated if you can help me with this . ----- Excess quoted text cut - see Original Post for more ----- You have several problems here. First, you're creating multiple instances of your component. You only need the one that you've created in MXML. Second, for your component to return a value to the main application, there are two ways that can be done - you're not doing either of them. Your main application can define a variable and bind it to the component's public property, so when that public property changes the application's variable changes as well. This is the easy way, but not really the best way for your component to send values to your application. The best way would be to have your component raise an event using a custom event class containing the values you want to send, and pass those values back to the main application via the event. Both of these approaches are covered in detail in the publicly-available tutorials, books and courses available for Flex. Dispatching a custom event: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf67fe7-7ffd.html Google "flex 4 custom event tutorial" for some examples. Finally, holy crap, you don't have to post the same question ten times. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, o thanks Dave , I binded the variable of my component to my main application's textInput with this code : <components:signIn_Up2 id="panelComp" includeIn="State1" correctUsername="@{testInput.text}"/> and it worked . but with custom events , I found this page : http://cookbooks.adobe.com/post_Very_simple_example_of_using_custom_events_to_pass-15466.html which is really helpful . but as you see in the code of that page it calls the "change" method of datagrid . what I need is something like data bindings that always listens and always connedted . is there a way to do that? thanks thanks , at last I did it . if I discuss the mechanism of sharing data between flex components and application in brief , it's like this . we define an actionscript class and it's like a container or some temp variable and it stores what we want and can be accessed by any components or applications in our project and we share the data with this actionscript class . here's a link about this process : http://cookbooks.adobe.com/post_Very_simple_example_of_using_custom_events_to_pass-15466.html hi , I have a flex application with one component . in that component I have defined a variable named "correctUsername" . after I click a button in the component I give a value to the correctUsername variable . and I want to have that value in my main application . but seems I can't do it in a way I'm doing it . the code is as below : my component is named "signIn" ------------------------- ..... <!-- signIn component --> <fx:script> public var correctUsername:String; ..... public function submitLogin():void{ correctUsername = "ok"; } ... </fx:script> ..... <s:Button label="myBtn" click="submitLogin()"/> --------------------------- --------------------------- my main application: .... <!-- my main application --> <fx:script> public var testSign:signIn; public funtion btnClick():void{ testSign = new signIn(); testInput.text = testSign.correctUsername; } </fx:script> .... <components:signIn id="myComponent"/> <s:TextInput id="testInput"/> <s:Button label="btn" click="btnClick()"/> ------------------------------------------ ------------------------------------------ anyone knows where the problem is? the thing that has mixed me up is that if I give the value of correctUsername variable in my component outside of any funtions it works fine and my main application shows the value correctly , but if I give it value inside any functions the main application doesn't show the value . I'll be appreciated if you can help me with this . hi , I have a flex application with one component . in that component I have defined a variable named "correctUsername" . after I click a button in the component I give a value to the correctUsername variable . and I want to have that value in my main application . but seems I can't do it in a way I'm doing it . the code is as below : my component is named "signIn" ------------------------- ..... <!-- signIn component --> <fx:script> public var correctUsername:String; ..... public function submitLogin():void{ correctUsername = "ok"; } ... </fx:script> ..... <s:Button label="myBtn" click="submitLogin()"/> --------------------------- --------------------------- my main application: .... <!-- my main application --> <fx:script> public var testSign:signIn; public funtion btnClick():void{ testSign = new signIn(); testInput.text = testSign.correctUsername; } </fx:script> .... <components:signIn id="myComponent"/> <s:TextInput id="testInput"/> <s:Button label="btn" click="btnClick()"/> ------------------------------------------ ------------------------------------------ anyone knows where the problem is? the thing that has mixed me up is that if I give the value of correctUsername variable in my component outside of any funtions it works fine and my main application shows the value correctly , but if I give it value inside any functions the main application doesn't show the value . I'll be appreciated if you can help me with this . hi , I have a flex application with one component . in that component I have defined a variable named "correctUsername" . after I click a button in the component I give a value to the correctUsername variable . and I want to have that value in my main application . but seems I can't do it in a way I'm doing it . the code is as below : my component is named "signIn" ------------------------- ..... <!-- signIn component --> <fx:script> public var correctUsername:String; ..... public function submitLogin():void{ correctUsername = "ok"; } ... </fx:script> ..... <s:Button label="myBtn" click="submitLogin()"/> --------------------------- --------------------------- my main application: .... <!-- my main application --> <fx:script> public var testSign:signIn; public funtion btnClick():void{ testSign = new signIn(); testInput.text = testSign.correctUsername; } </fx:script> .... <components:signIn id="myComponent"/> <s:TextInput id="testInput"/> <s:Button label="btn" click="btnClick()"/> ------------------------------------------ ------------------------------------------ anyone knows where the problem is? the thing that has mixed me up is that if I give the value of correctUsername variable in my component outside of any funtions it works fine and my main application shows the value correctly , but if I give it value inside any functions the main application doesn't show the value . I'll be appreciated if you can help me with this . hi , I have a flex application with one component . in that component I have defined a variable named "correctUsername" . after I click a button in the component I give a value to the correctUsername variable . and I want to have that value in my main application . but seems I can't do it in a way I'm doing it . the code is as below : my component is named "signIn" ------------------------- ..... <!-- signIn component --> <fx:script> public var correctUsername:String; ..... public function submitLogin():void{ correctUsername = "ok"; } ... </fx:script> ..... <s:Button label="myBtn" click="submitLogin()"/> --------------------------- --------------------------- my main application: .... <!-- my main application --> <fx:script> public var testSign:signIn; public funtion btnClick():void{ testSign = new signIn(); testInput.text = testSign.correctUsername; } </fx:script> .... <components:signIn id="myComponent"/> <s:TextInput id="testInput"/> <s:Button label="btn" click="btnClick()"/> ------------------------------------------ ------------------------------------------ anyone knows where the problem is? the thing that has mixed me up is that if I give the value of correctUsername variable in my component outside of any funtions it works fine and my main application shows the value correctly , but if I give it value inside any functions the main application doesn't show the value . I'll be appreciated if you can help me with this . hi , I have a flex application with one component . in that component I have defined a variable named "correctUsername" . after I click a button in the component I give a value to the correctUsername variable . and I want to have that value in my main application . but seems I can't do it in a way I'm doing it . the code is as below : my component is named "signIn" ------------------------- ..... <!-- signIn component --> <fx:script> public var correctUsername:String; ..... public function submitLogin():void{ correctUsername = "ok"; } ... </fx:script> ..... <s:Button label="myBtn" click="submitLogin()"/> --------------------------- --------------------------- my main application: .... <!-- my main application --> <fx:script> public var testSign:signIn; public funtion btnClick():void{ testSign = new signIn(); testInput.text = testSign.correctUsername; } </fx:script> .... <components:signIn id="myComponent"/> <s:TextInput id="testInput"/> <s:Button label="btn" click="btnClick()"/> ------------------------------------------ ------------------------------------------ anyone knows where the problem is? the thing that has mixed me up is that if I give the value of correctUsername variable in my component outside of any funtions it works fine and my main application shows the value correctly , but if I give it value inside any functions the main application doesn't show the value . I'll be appreciated if you can help me with this . hi , I have a flex application with one component . in that component I have defined a variable named "correctUsername" . after I click a button in the component I give a value to the correctUsername variable . and I want to have that value in my main application . but seems I can't do it in a way I'm doing it . the code is as below : my component is named "signIn" ------------------------- ..... <!-- signIn component --> <fx:script> public var correctUsername:String; ..... public function submitLogin():void{ correctUsername = "ok"; } ... </fx:script> ..... <s:Button label="myBtn" click="submitLogin()"/> --------------------------- --------------------------- my main application: .... <!-- my main application --> <fx:script> public var testSign:signIn; public funtion btnClick():void{ testSign = new signIn(); testInput.text = testSign.correctUsername; } </fx:script> .... <components:signIn id="myComponent"/> <s:TextInput id="testInput"/> <s:Button label="btn" click="btnClick()"/> ------------------------------------------ ------------------------------------------ anyone knows where the problem is? the thing that has mixed me up is that if I give the value of correctUsername variable in my component outside of any funtions it works fine and my main application shows the value correctly , but if I give it value inside any functions the main application doesn't show the value . I'll be appreciated if you can help me with this .
|
February 22, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||