5 Replies Latest reply on Mar 8, 2007 2:43 PM by theLoggerGuy

    Making a login system

    Anti-Girl
      Making a login system with flex.
      i have registration in one panel and login in another panel, basicly in the same application,
      But since il be calling the same username i register, i can only use the same id for that input feild in both REGISTRATION and LOGIN but i get a 'identifier already in use' , cant get my head for a work around.
      please help


      using something like this
      http://www.vipercreations.com/tutorials/Adobe%20Flex/28.html
        • 1. Re: Making a login system
          Anti-Girl Level 1
          i tried using different ids but i need to call another HTTPService for logging in, is that good practice?
          • 2. Re: Making a login system
            theLoggerGuy Level 1
            Can you post your code?
            • 3. Re: Making a login system
              ntsiii Level 3
              Don't re-declare the variable. Declare it once at the application level, then reference it as necessary from the components.

              Tracy
              • 4. Re: Making a login system
                Anti-Girl Level 1
                ntsii can u give me an example for declaring a textInput with an id at application level then refrencing it


                my code
                _____________________
                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
                <mx:states>
                <mx:State name="Logged In">
                <mx:SetProperty target="{panel1}" name="width" value="95%"/>
                <mx:SetProperty target="{panel1}" name="height" value="95%"/>
                <mx:RemoveChild target="{password}"/>
                <mx:RemoveChild target="{username}"/>
                <mx:RemoveChild target="{label1}"/>
                <mx:RemoveChild target="{Submit}"/>
                <mx:RemoveChild target="{label2}"/>
                <mx:SetProperty target="{panel1}" name="title" value="Members Section"/>
                <mx:AddChild relativeTo="{panel1}" position="lastChild">
                <mx:Label x="10" y="10" text="Welcome to the Members Section!"/>
                </mx:AddChild>
                <mx:AddChild relativeTo="{panel1}" position="lastChild">
                <mx:Label x="10" y="36" text="Here you can do great things, like join the forums @ Viper Creations!"/>
                </mx:AddChild>
                <mx:AddChild relativeTo="{panel1}" position="lastChild">
                <mx:Label x="10" y="62" text="Label"/>
                </mx:AddChild>
                </mx:State>
                </mx:states>
                <mx:Script>
                <![CDATA[
                import mx.rpc.events.ResultEvent;
                import mx.controls.Alert;
                ]]>
                </mx:Script>
                <mx:Script>


                <![CDATA[

                private function checkLogin(evt:ResultEvent):void
                {

                if(evt.result.loginsuccess == "yes")

                {

                currentState = "Logged In";

                }

                if(evt.result.loginsuccess == "no")

                {

                mx.controls.Alert.show('Invalid username/password');

                }
                }

                ]]>

                </mx:Script>
                <mx:HTTPService id="login_user" result="checkLogin(event)" showBusyCursor="true" method="POST" url=" http://www.phobos-machines.com/login/bin/request.php" useProxy="false">
                <mx:request xmlns="">
                <username>
                {username.text}
                </username>
                <password>
                {password.text}
                </password>
                </mx:request>
                </mx:HTTPService>

                <mx:Panel resizeEffect="Resize" width="250" height="200" layout="absolute" title="Login System" horizontalCenter="0" verticalCenter="-2" id="panel1">
                <mx:Label x="10" y="10" text="Username:" id="label1"/>
                <mx:TextInput x="10" y="36" id="username"/>
                <mx:Label x="10" y="66" text="Password:" id="label2"/>
                <mx:TextInput x="10" y="92" id="password" displayAsPassword="true"/>
                <mx:Button x="10" y="122" label="Submit" id="Submit" click="login_user.send();"/>
                </mx:Panel>






                <!--registraion -->

                <mx:HTTPService id="login" showBusyCursor="true" method="POST" url=" http://www.phobos-machines.com/login/bin/request.php" useProxy="false">
                <mx:request xmlns="">
                <username>
                {username2.text}
                </username>
                <password>
                {password2.text}
                </password>
                </mx:request>
                </mx:HTTPService>

                <mx:Panel x="30" y="10" width="380" height="270" layout="absolute">
                <mx:Form x="10" y="19" width="328" height="187">
                <mx:FormItem label="username">
                <mx:TextInput id="username2" width="100%"/>
                </mx:FormItem>

                <mx:FormItem label="Password">
                <mx:TextInput id="password2" width="100%" displayAsPassword="true"/>
                </mx:FormItem>
                <mx:FormItem>
                <mx:Button label="Submit" click="login.send(),Alert.show('User Registered', 'Registration',mx.controls.Alert.OK);"/>
                </mx:FormItem>
                </mx:Form>
                <mx:FormHeading x="0" y="0" label="Registration"/>
                </mx:Panel>



                </mx:Application>
                • 5. Re: Making a login system
                  theLoggerGuy Level 1
                  Anti-Girl. That's a complex little app you have there. There is an example of how to make a login screen with registration option shown here:
                  http://www.adobe.com/devnet/flex/quickstart/creating_states/

                  You'll need to combine it with your <httpRequest> statements, but it looks a little easier to follow.

                  But back to your question... Below is a simple example of how to programatically addressing a text input using its id "myTextInput". The app just copies the text from a text input control to a label field using a button as the trigger.

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical"
                  verticalAlign="middle" horizontalAlign="center">

                  <mx:Script>
                  <![CDATA[
                  private function showMyContent( ): void
                  {
                  myTextOutput.text = myTextInput.text;
                  }
                  ]]>
                  </mx:Script>

                  <mx:Panel title="textInput id example" width="200" height="200" verticalAlign="middle" horizontalAlign="center">
                  <mx:TextInput id="myTextInput" width="90%" text="Enter text here"
                  click="if ( myTextInput.text == 'Enter text here' ){myTextInput.text = '';}"/>
                  <mx:Button label="Copy to below" click="showMyContent();"/>
                  <mx:Label id="myTextOutput" width="90%"/>
                  </mx:Panel>

                  </mx:Application>