This is the personal weblog of Greg Burch.

Wednesday, July 03, 2002

Ok so around the days when I first started working with Flash Remoting, I was working with the FTree Component and filling it from a hierarchical structure on the back-end. It was basically an admin tool for editing the structure (adding nodes, deleting them, renaming them) I quickly ran into something that frightened me though, asynchronous calls. At the time I was always using the defaultResponder parameter when "getting" the service. So I had no way to take a delete action, know if it was successful and if so delete that node in the IDE. Several calls to the back-end are not guaranteed to fire the result handler in the same order. I could have modified the cfc to pass back the ID of the node that was deleted, but then I would have to walk my flash tree to find that id since the id's did not sync up. So I wrote this whole grand schema extending upon remoting to distinguish calls...waste of time. Here is the most elegant, simple way to handle my problem. (and possibly yours)

/* typical stuff */
NetServices.setDefaultGatewayURL("somegatewayurl.com");
gatewayConnection = Netservices.createGatewayConnection();

/* Look! No second parameter */ MyService = gatewayConnection.getService("some.service.here");

DeleteNodeHandler = function(node,tree){ this.node = node; this.tree_ref = tree; } DeleteNodeHandler.prototype.onResult = function(res){ if(res==false) return; /* Delete was a success, so remove the node this instance refers to */ this.tree_ref.removeNode(this.node); } function deleteNode(node){ /* since we never set a defaultResponder we can pass one in on each method call */ MyService.deleteNode(new DeleteNodeHandler(node,myTree), node.getData().id); }

So the process that happens here is this:

    1. The user requests to delete a node.
    2. The deleteNode function calls the server side deleteNode method and passes in a new DeleteNodeHandler, which takes the node id and a reference to the tree that its being deleted from. That new object stores that for later use. Then it passes the rest of the parameters that the server side will use (the id referring to the id on the back-end)
    3. If the method call returns anything but false (meaning it was successful at deleting the node from the server side structure) it continues on to delete it from our UI construct.

So now we can call deleteNode one thousand times in a row and its guaranteed to stay in sync with the back-end.
12:43:11 PM    comment []


© Copyright 2003 Greg Burch.
 
July 2002
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Jun   Aug

Home

Articles
Live Previews
Common Component Issues
Flash Remoting
SharedObjects
FlashVars
Extending Components
__resolve and apply
XML 2 DataProvider

Macromedia WebLogs
Jeremy Allaire
mesh on mx
jd on mx
An Architect's View

Other WebLogs
Peter Hall
Eric Dolecki
Flash the Future
jdb cyberspace
Branden Hall
OnRelease
Josh Dura
moik78
Full As A Goog
Flash Magazine
Claus Wahlers
Arul Kumaran
Phillip Torrone
Quasimondo
Guy Watson
Robert Hall


Resources
Macromedia Mobile Development Center

Books
Flash Design for Mobile Devices

Flash Enabled

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.