Hi Guys
I am trying to implement the login form . The login form works fine
when i use script and put all the action script in the main mxml file.
But my requirements is to put all the action script in external as
file and make things working. For some reason the builder does not
like my login button, user name text and password text in the as file.
Initially it does not recognize those components but then i user
parent::loginbutton to access which solves the compile time problem,
but gives type coercion error in my project as
"TypeError: Error #1034: Type Coercion failed: cannot convert
mx.containers::[EMAIL PROTECTED] to Namespace."
I like to define my login and password text input in the main mxml
file and like to write the business logic in external as file. 
Please let me know what i am missing.If you can provide someone who
has done that, that will be helpful too.
Thanks a lot for your help.
Anuj
/*My MXML Code*/
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas
        xmlns:mx="http://www.adobe.com/2006/mxml";
creationComplete="URLLoader_loadExample()"
        xmlns:text="flash.text.*" cornerRadius="2"
        xmlns:ns1="com.Pelco.login.view.*" width="1200" height="768">
            <!-- The Application class states property defines the view
states. -->
        <mx:Metadata>
        [Event(name="fistTimeSetupEvent", type="flash.events.Event")]
    </mx:Metadata>

<mx:Script source="scripts/login.as" />
<mx:HTTPService id="ConfigXMLService" url="Private/Config.xml"
resultFormat="e4x" result="loginSettings(event)" />         
<mx:HTTPService id="UsersXMLService" url="assets/Users.xml"
resultFormat="e4x" result="loginSettings(event)" />      
    <mx:states>
        <mx:State name="Recover">
            <!-- Add a TextInput control to the form. -->            
            <!-- Set properties on the Panel container and Button
control. -->            
            <mx:SetProperty target="{loginPanel}" 
                name="title" value="Recover Password"/>
            <mx:SetProperty target="{loginButton}" 
                name="label" value="Recover"/>

            <!-- Remove the existing LinkButton control. -->            
            <mx:RemoveChild target="{registerLink}"/>
            
            <!-- Add a new LinkButton control to change 
                view state back to the login form. -->            
            <mx:AddChild relativeTo="{spacer1}" position="before">
                <mx:LinkButton label="Return to Login"
click="currentState=''"/>
            </mx:AddChild>
            <mx:RemoveChild target="{formitem1}"/>
            <mx:SetProperty target="{password}" name="label"
value="Email:"/>
            <mx:AddChild relativeTo="{password}" position="before">
                <mx:FormItem label="or" textAlign="center"
horizontalCenter="true" horizontalAlign="center">
                </mx:FormItem>
            </mx:AddChild>
        </mx:State>
    </mx:states>
        
<mx:Panel width="1200" height="736" y="32" horizontalAlign="center"
verticalAlign="middle" creationComplete="ConfigXMLService.send()">

<!--<mx:Label text="here:{TabBarMain.enabled}"  fontSize="40" x="432"
y="10"/>
-->  <mx:Panel title="Login" id="loginPanel" 
            horizontalScrollPolicy="off" verticalScrollPolicy="off"
horizontalCenter="1" verticalCenter="1">
        <mx:Form id="loginForm" defaultButton="{loginButton}">
            <mx:FormItem label="Username:" id="username">
                <mx:TextInput id="txt_UserName"/>
            </mx:FormItem>
            <mx:FormItem label="Password:" id="password">
                <mx:TextInput id="txt_Password" displayAsPassword="true"/>
            </mx:FormItem>
            <mx:FormItem label="Domain:" id="formitem1">
                <mx:ComboBox
dataProvider="{domainCollection}"></mx:ComboBox>
            </mx:FormItem>
        </mx:Form>
        <mx:ControlBar>
            <!-- Use the LinkButton control to change to 
                the Register view state. -->                    
            <mx:LinkButton label="Forgot your password?" id="registerLink"
                click="currentState='Recover';"/>
            <mx:Spacer width="100%" id="spacer1"/>
            <mx:Button label="Login" id="loginButton"/>
        </mx:ControlBar>
    </mx:Panel>
</mx:Panel>

/*MyAction Script code*/
// ActionScript file
import mx.collections.XMLListCollection;
import mx.controls.Alert;
import mx.rpc.events.*;

import mx.controls.Alert;
import flash.net.URLLoader;
import flash.net.URLRequest;            
import flash.xml.*;
            
private var externalXML:XML;    
private var loader:URLLoader;
public var alert:Alert = new Alert;
public var alertPassword:Alert=new Alert;
public var tempUserName:Array=new Array();      
public var tempPassword:Array=new Array();

    public function URLLoader_loadExample():void
    {
        var request:URLRequest = new
URLRequest("Private/LoginAuthenticatedUsers.xml");  
        loader = new URLLoader();
        
        try 
        {
            loader.load(request);
        }
        catch (error:SecurityError)
        {
            trace("A SecurityError has occurred.");
        }
        //
        loader.addEventListener(Event.COMPLETE,processXML);
        
        function processXML(e:Event):void
        {   
                //Retrieving XML data and putting them in array                 
 
                
                externalXML = new XML(e.target.data);               
                for(var i:Number=0;i<externalXML.children().length();i++)
                {       
                        tempUserName.push(externalXML.user.userName.text()[i]); 
                        tempPassword.push(externalXML.user.password.text()[i]); 
        
                }                
        }
        
        //Clicking Log-in button 
        
       
parent::loginButton.addEventListener(MouseEvent.CLICK,checkLogin);   
        function checkLogin( event:MouseEvent):void
        {
                var chkUserName:Boolean;
                var chkPassWord:Boolean;                
                
                //Validating User Name and Password
                for(var j:Number=0;j<tempUserName.length;j++)
                {
                
if((parent::txt_UserName.text==tempUserName[j].toString())&&(parent::txt_UserName.text!=""))
                        {
                                chkUserName=true;
                                
if((parent::txt_Password.text==tempPassword[j].toString())
&&(parent::txt_Password.text!=""))
                                {
                                        chkPassWord=true;                       
                        
                                        alert=Alert.show("You have entered 
correct user name and
password");
                                }
                                else
                                {
                                                alert=Alert.show("Wrong 
password");
                                }
                        }                                                       
                        
                }       
                //Checking for null and wrong user name and password
                if((!chkUserName)&&(!chkPassWord))
                {
                        alert=Alert.show("Please Check the Credentials");       
                }
        }
    }   



Reply via email to