The remoteObject is asyncronous. This means that Flex sends the request off to the server and keeps going. The result of
myRemoteObject.existRecord.send(myRecord) will always be true if Flex managed to send the request to the server. When the result comes back, Flex jumps to the function you have set. You will need to add your logic to the handler function you have set up. The way I would do it is to send the record. If the record already exists, send an error message back. If it doesn't exist, add it and send a success message back. This way, you only send the data once. --- In [email protected], "secrit.service" <secrit-serv...@...> wrote: > > > 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 >

