0 Replies Latest reply on Aug 4, 2009 9:07 AM by EvolvedDSM

    Handling ResultEvent for data service methods?

    EvolvedDSM Level 2

      I have a dataservice (ds) that makes use of createItem(obj) and deleteItem(obj).  When I call either of these methods, I want to be able to determine which method is being called and then take an action depending on which was performed..

       

      Here's what I'd like to do...

       

      ds.addEventListener(ResultEvent.RESULT, dsHandler);

       

      private function dsHandler(event:ResultEvent):void{

      if(<the ds created an object>){

      ...do this....

      } else if(<the ds deleted the object>){

      ...do something else...

      }

       

      So how can I write this to do as I described above?  I've read a little bit about using tokens, but I'm not sure if this is the direction I need to be going towards.

       

      I saw an example of

      private var token:AsyncToken;

      ...

      token = ds.createItem(obj);

      token.kind = "create";

      ds.createItem(obj);

       

      and then...

      private function dsHandler(event:ResultEvent):void{

      if(event.token.kind == "create"){

      ...do this....

      } else if(event.token.kind == "delete"){

      ...do something else...

      }

       

      This kinda worked for me, except I kept getting an error that said "Item with id 'CEAD6420-6E28-B2B3-10C9-E62770B9BD13' already exists.  Error on destination 'ds' "  Without this code, I get no error.  The weird thing is that it still creates the item even if it reports the error.  So why is this happening?

       

      Any help is appreciated.  thanks!