Flex 4.5 Mobile Login Form needs 2 clicks?
I have been working on developing an application for the android market thta firstly requires the users to login to a account. I have put the code together below, along with a data link to a database in order to check the credentials. However the application does not switch to the second view on the first click of the "Login" button however it seems to take 2 or more clicks sometimes. I presume as it is fetching data from a database that it takes time to be开发者_JS百科 verifies, could someeone tell me how to solve this and maybe implement a BusyIndicator along with it?
<![CDATA[
protected function login_btn_clickHandler(event:MouseEvent):void
{
var match:Boolean;
getEmployeesByNameResult.token = employeeService.getEmployeesByName(usr_nme_txtbox.text, pass_txtbox.text);
if (getEmployeesByNameResult.lastResult != null)
{
navigator.pushView(HomeView, getEmployeesByNameResult.lastResult.id);
}
}
]]>
<s:Button id="login_btn" width="100%" label="Login"
click="login_btn_clickHandler(event)"/>
showBusyIndicator is a property on the main service classes used in Flex apps. I would expect it to also work on Android, in theory, but in practice I'm not sure mobile app will have a mouse cursor. You should be able to work something out to have some animated "Wait" object.
What service class are you using? ( HTTPService; RemoteObject; or WebService? )
I'll point out that the service classes in Flex are asynchronous; not synchronous like your code tries to use it. So, when you run this code:
getEmployeesByNameResult.token = employeeService.getEmployeesByName(usr_nme_txtbox.text, pass_txtbox.text);
if (getEmployeesByNameResult.lastResult != null)
{
navigator.pushView(HomeView, getEmployeesByNameResult.lastResult.id);
}
your getEmployeesByNameResult.lastResult value is most likely null; unless your service call has 0 process time and 0 latency (Both are unlikely). You should listen for the result event on the service:
protected function login_btn_clickHandler(event:MouseEvent):void
{
var match:Boolean;
getEmployeesByNameResult.addEventListener(ResultEvent.RESULT, onResult);
getEmployeesByNameResult.showBusyCursor = true;
getEmployeesByNameResult.token = employeeService.getEmployeesByName(usr_nme_txtbox.text, pass_txtbox.text);
}
protected function onResult(event:ResultEvent):void
{
if (getEmployeesByNameResult.lastResult != null)
{
navigator.pushView(HomeView, getEmployeesByNameResult.lastResult.id);
}
}
精彩评论