Hi all,
I have following issue, which I don't understand.
I created a button which will add a record to the database. But before
doing so I need to check if a similar record already exists.
This is how I thought it could be solved:
<mx:RemoteObject id="myRemoteObject">
<mx: method name ="existRecord" result
="recordExistResultHandler(event)"/>
<mx:RemoteObject/>
if (myRemoteObject.existRecord.send(myRecord)) {
Alert.show ("Record already exists")
} else {
// Insert record into the database
myRemoteObject.insertRecord.send(myRecord)
}
private function recordExistResultHandler (evt:ResultEvent) : Boolean {
Alert.show ("Result getting back from webserver is " +
evt.result.toString());
return evt.result;
}
The function existRecord on the webserver checks if a similar record
already exists and sends a Boolean back. This works fine.
To my opinion this should work as follows (supposing record is already
in the database) :
- Before executing my if-statement, it will check the condition (check
if record already exists)
- it send a request existSpell to the webserver which will query the
database
- num_rows is greater dan zero (meaning record already exists), the
webserver will return TRUE to the resultHandler of flex-application
- resultHandler is executed --> an Alert-windows appears telling "Result
getting back .......is TRUE " and the value is returned to the
if-statement.
- Because condition is true --> an Alert-window appears telling "Record
already exists"
BUT ... THIS IS NOT HOW IT WORKS ?????
As a matter of fact the if-statement is executed first (Alert 'Record
already exists') and afterwards I get the Alert telling the result of
the webserver???
It's the opposite world.
Am I missing something??
Thanks