DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Some Flex Code

09.18.2007
| 5588 views |
  • submit to reddit
        // A login box component in mxml.  This is buggy, I'll adjust this to the clean stuff when I get it figured out.
<?xml version="1.0" encoding="UTF-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" label="Login">
  <mx:Form labelWidth="150">
  <mx:Metadata> 
      [Event(name="login", type="com.pomodo.events.LoginEvent")] 
  </mx:Metadata> 
  <mx:Script> 
  <![CDATA[ 
    import mx.controls.Alert; 
    import mx.rpc.events.ResultEvent;
    import com.pomodo.events.LoginEvent; 
      private function login():void { 
          svcAccountLogin.send({login: loginTI.text, password: passwordTI.text}); 
      } 
      private function handleAccountLoginResult(event:ResultEvent):void { 
          var result:Object = event.result; 
          if (result == "badlogin") { 
              Alert.show("The username or password is wrong.", "Login Error"); 
          } else { 
              dispatchEvent(new LoginEvent(XML(result))); 
          } 
      } 
  ]]> 
  </mx:Script> 
  <mx:HTTPService 
      id="svcAccountLogin" 
      url="/sessions/create_xml" 
      resultFormat="e4x" 
      method="POST" 
      result="handleAccountLoginResult(event)"/>

    <mx:FormItem label="Username" required="true">
      <mx:TextInput id="loginTI"/>
    </mx:FormItem>
    <mx:FormItem label="Password" required="true">
      <mx:TextInput id="passwordTI"/>
    </mx:FormItem>
    <mx:FormItem>
      <mx:Button id="loginButton" label="Login" click="login()"/> 
    </mx:FormItem>
  </mx:Form>
</mx:VBox>