17.3. Validating Receipt of Communication Over a Local Connection
Problem
You want a sending movie to receive confirmation that the communication was successfully received.
Solution
Configure the receiving movie to return a receipt to the sending movie.
Discussion
If you need to confirm that a communication was received, you can have the receiving movie send a message back to the original sending movie. Here are the steps for confirming receipt of a communication:
Set up the sending and receiving movies, as described in Recipe 17.1.
In addition to whatever code you include in the method that is invoked on the receiving movie, write code to send a receipt over a new channel (e.g., “_myConnectionReceipt”). You can use
this.send( )within the local connection’s method to send a receipt back to the original sender.In the sending movie, call the
connect( )method, passing it the name of the channel over which the receiving movie sends the receipt (again, “_myConnectionReceipt”).In the sending movie, create a method on the local connection object to handle the receipt communication. Make sure this method name matches the name of the method that the receiving movie invokes when sending the receipt.
The following is an example of some code from a sending movie and a receiving movie.
First, the receiving movie code:
// Create the receiving code to listen on the "_myConnection" channel. lc = new LocalConnection( ); lc.connect("_myConnection"); lc.myMethod = function ( ) { // In addition to whatever ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access