I am trying to assign a value from my database to a variable inside my Flex application. So far I read up a few ideas and I have at the moment the following code using a PHP web service:
protected function btnSubmitUser_clickHandler(event:MouseEvent):void
{
username = txtUsername.text;
password = txtPassword.text;
serialno = txtSerialNo.text;
userName.writeUTFBytes(username);
passWord.writeUTFBytes(password);
serialNo.writeUTFBytes(serialno);
EncryptedLocalStore.setItem("Username", userName);
EncryptedLocalStore.setItem("Password", passWord);
EncryptedLocalStore.setItem("Serial", serialNo);
getRepnameByUsernameResult2.addEventListener(ResultEvent.RESULT, onMyResult);
getRepnameByUsernameResult2.token = repnameService.getRepnameByUsername(username);
}
protected function onMyResult(event:ResultEvent):void{
repServ = getRepnameByUsernameResult2.lastResult as Repname;
repid = repServ.RepID;
RepID.writeInt(repid);
EncryptedLocalStore.setItem("Rep", RepID);
lblTestRep.text = RepID.toString();
}
The label is a test label to see if the data is being assigned correctly. Unfortunately, I am getting errors with this where it declares:
Error #1009: Cannot access a property or method of a null object reference.
at views::SettingsView/onMyResult()[C:\Users\Justin\Adobe Flash Builder 4.6\Rep Aware\src\views\SettingsView.mxml:62]
This error is found at repid = repServ.RepID; of the above code.
Any help as to what I am doing wrong would be appreciated.
That error means that
repServisnull. So the propertylastResultin:is either
null, or is not of typeRepname.The second option is possible because casting an object to an unrelated type using
asreturnsnull. The same cast would throw an exception if you do it like this: