PDA

View Full Version : newB AS3 + Flex 2 prob


gutaker
10-21-2006, 04:36 PM
hi there...
im writing a script to post a login form to php after a click and after verification php renturns something like this: <loginstate>ok</loginstate>

here is the code:


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function costam(): void {
loginRequest.send();
switch(loginRequest.lastResult.loginstate) {
case "ok":
Alert.show("You have been logged in...", "Login info");
break;
case "error":
Alert.show("Login failed, please try again!", "Login info");
break;
}
}
]]>
</mx:Script>
<mx:HTTPService showBusyCursor="true" id="loginRequest" method="POST" useProxy="false" url="http://venomnote/php/user_verify.php">
<mx:request xmlns="">
<uname>
{uname.text}
</uname>
<passwd>
{passwd.text}
</passwd>
</mx:request>
</mx:HTTPService>
<mx:Dissolve id="dissolveOut" duration="1000" alphaFrom="1.0" alphaTo="0.0"/>
<mx:Dissolve id="dissolveIn" duration="1000" alphaFrom="0.0" alphaTo="1.0"/>
<mx:TitleWindow visible="{cblbox.selected}" showEffect="{dissolveIn}" hideEffect="{dissolveOut}" id="titwin" width="294" height="156" layout="absolute" title="Login Box" showCloseButton="false" horizontalCenter="1" verticalCenter="0" cornerRadius="0" alpha="0.5">
<mx:Form horizontalCenter="0" verticalCenter="0">
<mx:FormItem label="Username">
<mx:TextInput id="uname"/>
</mx:FormItem>
<mx:FormItem label="Password">
<mx:TextInput displayAsPassword="true" id="passwd"/>
</mx:FormItem>
<mx:Button label="Login" width="235" click="costam();" id="button1"/>
</mx:Form>
</mx:TitleWindow>
<mx:ApplicationControlBar dock="{cbdock.selected}" horizontalCenter="0" bottom="50" width="75%">
<mx:HBox width="100%" verticalAlign="middle" horizontalAlign="left">
<mx:CheckBox id="cbdock" label="Docked"/>
<mx:CheckBox id="cblbox" label="Login Box"/>
</mx:HBox>
<mx:HBox width="100%" verticalAlign="middle" horizontalAlign="right">
<mx:Label text="Control Bar"/>
</mx:HBox>
</mx:ApplicationControlBar>
</mx:Application>
what bothers me is this msg:


TypeError: Error #1009: Cannot access a property or method of a null object reference.
at test/::costam()
at test/__button1_click()

i'm total newB in as3 and flex 2, but im intermediate PHP and Delphi programmer, so please try not to yell at me :)

thx

skomi101
10-26-2006, 06:35 AM
Try with listener.

Add this to first line creationComplete="onInit();" and this listener to SCRIPT section

private function onInit():void{
loginButton.addEventListener(MouseEvent.CLICK, submitLogin, false, 0);
}

xmark99
11-07-2006, 09:13 PM
The reason is that you are trying to access the result from the HTTPService too early. The result has not come back yet. The best practice when using services is as follows:

Modify your HTTPService call to add a result handler

<mx:HTTPService showBusyCursor="true" id="loginRequest" method="POST" useProxy="false" url="http://venomnote/php/user_verify.php" result="onLoginRequestResult(event)">


Then handle the result in your newly created handler

private function onLoginRequestResult(event:ResultEvent):void {
switch(event.result.loginstate) {
case "ok":
Alert.show("You have been logged in...", "Login info");
break;
case "error":
Alert.show("Login failed, please try again!", "Login info");
break;
}
}


Remember to remove the switch code from your other costam() function.

gutaker
02-27-2007, 09:02 AM
its maybe late to thank but thx :)