9 Replies Latest reply on Apr 21, 2010 8:14 PM by mroiler

    Help!

    mroiler Level 1

      Hi,

      I am running Flash  Builder 4 Beta 2 and I am trying to make a login. Each member has a  different page. I found a tutorial in one of the adobe cookbooks but it  just set it up for one genaral page. When i try to log in, it knows I  have a correct login but I can't figure out how to get it to the page. I  tried databinding my username text property to the current state  property, but i got an actionscript error. This my script block.

       

            <fx:Script>
              <![CDATA[
                   import mx.controls.Alert;
                  import  mx.rpc.events.ResultEvent;
                 
                  public  function buttonlogin_clickHandler(event:ResultEvent):void
                   {
                      if(event.result.loginsuccess == "yes")
                       {
                          currentState = "{username.text}";
                      }
                       if(event.result.loginsuccess == "no")
                      {
                           Alert.show("Invalid username/password");
                      }   
                   }
                 
              ]]>
          </fx:Script>

        • 1. Re: Help!
          msakrejda Level 4

          That's not how binding works in ActionScript: take a look at BindingUtils. That said, I don't think you need binding here--try taking out the double quotes

          and the curly braces (i.e., currentState = username.text; ).

          1 person found this helpful
          • 2. Re: Help!
            mroiler Level 1

            I got this actionscript error when I ran it using the username dev.

             

            ArgumentError: Undefined state 'username.text'.
                at mx.core::UIComponent/getState()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UI Component.as:9908]
                at mx.core::UIComponent/findCommonBaseState()[E:\dev\4.0.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9928]
                at mx.core::UIComponent/commitCurrentState()[E:\dev\4.0.0\frameworks\projects\framework\src\ mx\core\UIComponent.as:9750]
                at mx.core::UIComponent/setCurrentState()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:9701]
                at mx.core::UIComponent/set currentState()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:6087 ]
                at components::login/buttonlogin_clickHandler()[C:\Documents and Settings\HP_Administrator\Desktop\flex stuff\Mroilers.com_Member_Area\src\components\login.mxml:17]
                at components::login/__login_user_result()[C:\Documents and Settings\HP_Administrator\Desktop\flex stuff\Mroilers.com_Member_Area\src\components\login.mxml:28]
                at flash.events::EventDispatcher/dispatchEventFunction()
                at flash.events::EventDispatcher/dispatchEvent()
                at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.0.0\frameworks\pro jects\rpc\src\mx\rpc\http\HTTPService.as:989]
                at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.0.0\frameworks\projec ts\rpc\src\mx\rpc\AbstractInvoker.as:318]
                at mx.rpc::Responder/result()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:5 6]
                at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\AsyncR equest.as:84]
                at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\ messaging\channels\DirectHTTPChannel.as:446]
                at flash.events::EventDispatcher/dispatchEventFunction()
                at flash.events::EventDispatcher/dispatchEvent()
                at flash.net::URLLoader/onComplete()

            • 3. Re: Help!
              msakrejda Level 4

              Remove the quotes around username.text

              1 person found this helpful
              • 4. Re: Help!
                mroiler Level 1

                I tried that and got the same error.

                • 5. Re: Help!
                  mroiler Level 1

                  Ok, I tried it again using the username dev, and got a different error. I do have a state named dev.

                   

                  ArgumentError: Undefined state 'dev'.
                      at mx.core::UIComponent/getState()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UI Component.as:9908]
                      at mx.core::UIComponent/findCommonBaseState()[E:\dev\4.0.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9928]
                      at mx.core::UIComponent/commitCurrentState()[E:\dev\4.0.0\frameworks\projects\framework\src\ mx\core\UIComponent.as:9750]
                      at mx.core::UIComponent/setCurrentState()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:9701]
                      at mx.core::UIComponent/set currentState()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:6087 ]
                      at components::login/buttonlogin_clickHandler()[C:\Users\HP\Adobe Flash Builder 4\Mroilers.com_Member_Area\src\components\login.mxml:17]
                      at components::login/__login_user_result()[C:\Users\HP\Adobe Flash Builder 4\Mroilers.com_Member_Area\src\components\login.mxml:28]
                      at flash.events::EventDispatcher/dispatchEventFunction()
                      at flash.events::EventDispatcher/dispatchEvent()
                      at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.0.0\frameworks\pro jects\rpc\src\mx\rpc\http\HTTPService.as:989]
                      at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.0.0\frameworks\projec ts\rpc\src\mx\rpc\AbstractInvoker.as:318]
                      at mx.rpc::Responder/result()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:5 6]
                      at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\AsyncR equest.as:84]
                      at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\ messaging\channels\DirectHTTPChannel.as:446]
                      at flash.events::EventDispatcher/dispatchEventFunction()
                      at flash.events::EventDispatcher/dispatchEvent()
                      at flash.net::URLLoader/onComplete()

                  • 6. Re: Help!
                    msakrejda Level 4

                    Not according to the compiler . Can you post the relevant code?

                    • 7. Re: Help!
                      mroiler Level 1

                          <s:states>
                              <s:State name="main"/>
                              <s:State name="dev"/>
                          </s:states>
                          <fx:Script>
                              <![CDATA[
                                  import mx.rpc.events.ResultEvent;
                                 
                                  public function buttonlogin_clickHandler(event:ResultEvent):void
                                  {
                                      if(event.result.loginsuccess == "yes")
                                      {
                                          currentState = username.text;
                                      }
                                      if(event.result.loginsuccess == "no")
                                      {
                                          Alert.show("Invalid Username or Password");
                                      }   
                                  }

                       

                              ]]>
                          </fx:Script>

                      • 8. Re: Help!
                        mroiler Level 1

                        I went and tried it again and it worked perfectly. This was on a different computer though. Thanks!

                        • 9. Re: Help!
                          mroiler Level 1

                          Hi, I know this question is closed but I suddenly got another problem and I have no idea why. When I click on the Buttton with an id of buttonlogin using correct credentials nothing happens.

                           

                          <fx:Script>
                                  <![CDATA[

                                      import mx.rpc.events.ResultEvent;
                                     
                                      public function buttonlogin_clickHandler(event:ResultEvent):void
                                      {
                                          if(event.result.loginsuccess == "yes")
                                          {
                                              currentState=username.text;
                                          }
                                          if(event.result.loginsuccess == "no")
                                          {
                                              Alert.show("Invalid Username or Password");
                                          }   
                                      }

                                    ]]>
                              </fx:Script>

                          <fx:Declarations>
                                  <s:HTTPService
                                      id="login_user"
                                      result="buttonlogin_clickHandler(event)"
                                      url="data/login.php">
                                      <mx:request>
                                          <username>{username.text}</username>
                                          <password>{password.text}</password>
                                      </mx:request>
                                  </s:HTTPService>

                          </fx:Declarations>

                          <s:Panel width="247" height="146" title="Login">
                                              <mx:Form x="-6" y="-5">
                                                  <mx:FormItem label="Username:">
                                                      <s:TextInput id="username"/>
                                                  </mx:FormItem>
                                                  <mx:FormItem label="Password:">
                                                      <s:TextInput id="password"
                                                                   displayAsPassword="true"/>
                                                  </mx:FormItem>
                                                  <mx:FormItem>
                                                      <s:Button id="buttonlogin"
                                                                label="Login"
                                                                click="login_user.send()"/>
                                                  </mx:FormItem>
                                              </mx:Form>
                                       </s:Panel>