2 Replies Latest reply on Mar 6, 2008 4:31 AM by Gregory Lafrance

    Custom Components

    cukiee
      Hi,
      I m very new to Flex just a weeks time
      I have a requirement wherein there are 2 custom components created one is the LoginBox and other one is simple textarea. Both are placed on to the main application
      The requirement is as such I have to get the name and password from component one and display it on the textarea i.e component 2 on the click button of the LoginBox component during run time

      Kindly help

      Thanks and Regards
      Priya
        • 1. Re: Custom Components
          Karl_Sigiscar_1971 Level 3

          Use MVC and all your components will be able to use the same model.

          So, your login and password (as all the data or state in your application) will be stored in the model. The model, as it is a singleton, will be accessible from anywhere in your application.

          Investigate Cairngorm.
          • 2. Re: Custom Components
            Gregory Lafrance Level 6
            --------------------- comp/LoginBox.mxml --------------------------
            <?xml version="1.0" encoding="utf-8"?>
            <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">
            <mx:Form>
            <mx:FormItem label="User Name">
            <mx:TextInput id="user"/>
            </mx:FormItem>
            <mx:FormItem label="Password">
            <mx:TextInput id="pwd" displayAsPassword="true"/>
            </mx:FormItem>
            </mx:Form>
            </mx:VBox>
            ------------------------- comp/InfoDisplay.mxml ---------------------
            <?xml version="1.0" encoding="utf-8"?>
            <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">
            <mx:TextArea id="txtArea" width="100%" height="100%"/>
            </mx:VBox>
            --------------------------- Test.mxml --------------------------
            <?xml version="1.0"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:myComp="comp.*">
            <mx:Script>
            <![CDATA[
            private function clickHandler():void{
            display.txtArea.text = "User: " + login.user.text
            + "\nPassword: " + login.pwd.text;
            }
            ]]>
            </mx:Script>
            <myComp:LoginBox id="login"/>
            <myComp:InfoDisplay id="display"/>
            <mx:Button label="Display Information" click="clickHandler()"/>
            </mx:Application>