0

I'm using Flex 4.6 with php and MySQL to develop a browser-based app. After login, the application populates an ArrayCollection (called cueArray) of cueItem objects with RemoteObject from my php class.

I have a List with a custom ItemRenderer which is bound to cueArray. The ItemRenderer has two buttons, Complete and Cancel. When cancel is clicked, the particular cueItem.state variable (called by changing the data.state inside the ItemRenderer) is changed from 'cued' to 'cancelled'. An eventListener on cueArray then triggers a changeEvent that updates the data with RemoteObject and then removes the clicked cueItem object from cueArray.

The trick is that if the RemoteObject call fails (because of a broken connection) the state should be changed back to 'cued' and the item should not be removed from cueArray. If the result event handler is called, the item should be removed from cueArray.

The problem is that in the Result and Fault event handlers, I do not have access to which cueArray item was clicked. I realise that there are workarounds, but I am looking for a graceful solution. For instance, in the Result event handler I can have my php function return the ID of the cueItem that was changed, but that does not solve my problem with the Fault handler.

Do you have any ideas?

Thank you in advance!

Ian

Ian
  • 1

1 Answers1

0

Target and currentTarget will return references to remoting stuff. You won't be able to avoid a getCueItemByID method, as the event propagation chain is broken when you call a remote service. You can also store the pending cueItems in a dynamic object, and finally get them back on Fault or Result (the following is just an example, there are missing part since I don't know how you manage your items):

private var pendingItems:Object = {};

private function onCueArrayChange(event:CollectionEvent):void
{
    // No idea how you get your current cueItem...
    item = getConcernedItem();

    pendingItems[item.id] = item;
    remoteCall();
}

private function onFault():void
{
    var myItem = pendingItems[myId];
}
LoremIpsum
  • 4,328
  • 1
  • 15
  • 17