tags:

views:

75

answers:

1

In my Main application I used label (like id=firstname) so we can use in main used firstname.text for databinding. But I have created canves custom component and load in main application using viewstack.
In canves custom component how can I Bind label(id=firstname).

I tried:
var username:string = firstname.text but not show undefine firstname.
How can I access all label and component in Main application to custom application. Please refer any URL.

+1  A: 

In short, you use binding. Add a property called firstname to CustomComponent.mxml and bind it to your firstnameTextbox:

<mx:Script>
    <![CDATA[
        private var _firstname : String;

        [Bindable] // only required on getter
        public function get firstname() : String
        {
            return _firstname;
        }

        public function set firstname(value : String) : void
        {
            _firstname = value;
        }
    ]]>
</mx:Script>
<mx:Textbox id="firstnameTextBox" text="{firstname}" />

Then, you bind the firstname to a value in your main.mxml:

<mx:Application>
    <mx:Script>
        <![CDATA[
            [Bindable]
            private var _firstname : String;
        ]]>
    </mx:Script>
    <cs:CustomComponent id="customComponent" firstname="{_firstname}" />
</mx:Application>

Now, whenever you change _firstname in Main.mxml, it will automatically filter up to the textbox in your custom component.

Richard Szalay
thanks Richard Szalay . But show Data binding will not be able to detect assignments to "_firstname"
R.Vijayakumar
thanks thanks Richard Szalay . It is working
R.Vijayakumar
[Bindable] actually causes the compiler to generate wrapping code around the member so it will still be able to detect assignments.
Richard Szalay