Hi, I have written a function and after checking the username and password, to toggle the buttons, but I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference. Here is the function I wrote public function checkCredentials():void { if(loginWin1.userInput.text == 'funandlearning' && loginWin1.passwordInput.text == 'funandlearning') { Alert.show("Login Successful"); PopUpManager.removePopUp(loginWin1); //var main:Main = new Main(); main.logout.visible = false; } else { Alert.show('Try again'); PopUpManager.removePopUp(loginWin1); } } LoginPopUp contains the code for displaying on the popupwindow, and Main is another component which contains code for calling popup window and it contain other UI code for header. Is this the right way to do? Thanks ________________________________ From: Omotola Anjorin <shot2f...@yahoo.com> To: flexcoders@yahoogroups.com Sent: Mon, November 9, 2009 6:33:48 AM Subject: Re: [flexcoders] Passing values from popup window to MXML component Yeah you can do what rohit said by adding a logout button at the same place and toggling the visiblity. This way, >From you main application you can do something like this. if(loginWin. userInput. text=='funandlearni ng' && loginWin.passwordIn put.text= ='funandlearning' ) { Alert.show(" Login Successful") ; loginWin.loginButto n.visible = false loginWin.logoutButt on.visible = true } You can also use the same button but play around the text property. Cheers ________________________________ From: Rohit Sharma <rohit.sharma1982@ gmail.com> To: flexcod...@yahoogro ups.com Sent: Mon, November 9, 2009 12:21:02 PM Subject: Re: [flexcoders] Passing values from popup window to MXML component You can add a logout button at the same place as login button and toggle the visibilities of these buttons depending upon the state of your component. On Mon, Nov 9, 2009 at 9:58 AM, Funand Learning <funandlearning3@ yahoo.com> wrote: > > > > > > > > > > > > > > > > >> > >> > >Hello All, > >I was trying to create a login Page. The page has one main MXML application >file with couple of MXML components. The First component contains the >following: > >Component1.mxml: > ><?xml version="1.0" encoding="utf- 8"?> > > width="60%" height="261"> > > <mx:Script> > <![CDATA[ >> import mx.managers. PopUpManager; > import mx.controls. Alert; > import > components.LoginPop Up; > import mx.events.CloseEven t; > > public var loginWin:LoginPopUp ; > > private function loginHandler( ):void { > loginWin = new LoginPopUp() ; >> loginWin.addEventLi stener(CloseEven t.CLOSE,closeHan dler); > PopUpManager. addPopUp( loginWin, this,true) ; > PopUpManager. centerPopUp( loginWin) ; > > > } > > public function closeHandler( event:CloseEvent ):void > { > PopUpManager. removePopUp( loginWin) ; > > } > >> > public function checkCredentials( ):void{ > > > if(loginWin. userInput. text=='funandlearni ng' && loginWin.passwordIn > put.text= ='funandlearning' ) > { > Alert.show(" Login Successful") ; > >> } > else > { > Alert.show(" Login Failed"); > } > } > > > > ]]> > </mx:Script> > > > > <mx:HBox width="90%" height="55" borderColor= "#F85023" id="headerButtons" > borderStyle= "outset" horizontalAlign= "left" verticalAlign= "middle" >> backgroundColor= "#938480"> > <mx:Spacer width="10%"/> > <mx:Button id="loginMain" label="Login" click="loginHandler ( )"/> > <mx:Button id="logout" label="LogOut" /> >> </mx:HBox> > > <mx:HBox width="100%" height="82%"> > <mx:HBox width="25%" > height="82%" borderStyle= "outset" borderColor= "#F85023"> > </mx:HBox> > <mx:HBox width="65%" height="82%" borderColor= "#F85023" borderStyle= > "outset"> >> </mx:HBox> > </mx:HBox> ></mx:VBox> > >component2.mxml has the following code for the popup > ><?xml version="1.0" encoding="utf- 8"?> > >> xmlns:main=" components. *" layout="vertical" > title="Please login" showCloseButton= "true"> > > <!-- defined state to toggle between register and login > --> > <mx:states> > <mx:State name="Register" basedOn=""> > <mx:AddChild relativeTo=" {loginForm} " > position="lastChild " creationPolicy= "all"> >> <mx:FormItem label="Email"> > <mx:TextInput id="email"/> > </mx:FormItem> > </mx:AddChild> > >> <mx:SetProperty > target="{loginButto n}" name="label" value="Register" /> > <mx:RemoveChild target="{registerLi nk}"/> > > <mx:AddChild relativeTo=" {linkSpacer} " position="before"> >> <mx:LinkButton label="Return to Login" click="currentState >> ='';this. title='Please Login'"/> > </mx:AddChild> > </mx:State> >> </mx:states> > <mx:Script> > <![CDATA[ > import > mx.events.CloseEven t; > import mx.managers. PopUpManager; > import mx.controls. Alert; > > > ]]> > </mx:Script> > <mx:Form id="loginForm"> >> <mx:FormItem label="Username: "> > <mx:TextInput id="userInput" /> > </mx:FormItem> > <mx:FormItem label="Password: "> > <mx:TextInput id="passwordInput" displayAsPassword= "true"/> >> > </mx:FormItem> > > </mx:Form> > <mx:ControlBar> > <mx:LinkButton > label="Need to Register?" id="registerLink" > click="currentState ='Register' ;this.title= 'Register' " >> /> > <mx:Spacer width="100%" id="linkSpacer" /> > <mx:Button label="Login" id="loginButton" click="checkCredent ials( > )"/> > <mx:Button label="Cancel" click="PopUpManager . removePopUp( this)"/> >> </mx:ControlBar> > ></mx:TitleWindow> > >I need help in knowing how to change the login button in > component1.mxml to logout button when the login functionaility from the > popuup window is successful > >Thanks. > >