> 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 .

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/flex/message.cfm/messageid:6538
Subscription: http://www.houseoffusion.com/groups/flex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/flex/unsubscribe.cfm

Reply via email to