[ Team LiB ] |
Recipe 17.3 Validating Receipt of Communication Over a Local Connection17.3.1 ProblemYou want a sending movie to receive confirmation that the communication was successfully received. 17.3.2 SolutionConfigure the receiving movie to return a receipt to the sending movie. 17.3.3 DiscussionIf 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:
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 other code goes in the // receiving method, add this code to issue a receipt // back to the sending movie over the "myConnectionReceipt" channel. // The this keyword refers to the current local connection object. this.send("_myConnectionReceipt", "onReceipt"); }; Then, the sending movie code: // Create the local connection object for sending over the "_myConnection" channel. sending_lc = new LocalConnection( ); sending_lc.send("_myConnection", "myMethod"); // Tell the local connection to listen on the "_myConnectionReceipt" channel for the // receipt broadcast by the receiving movie. sending_lc.connect("_myConnectionReceipt"); // Define the onReceipt( ) method that gets called from the receiving movie. sending_lc.onReceipt = function ( ) { _root.output_txt.text = "received"; }; The key point is that the name of the channel on which a local connection object listens (using connect( )) must be the same as the name of the channel over which another movie's local connection object sends a message (using send( )). Also, notice that the two movies do not communicate back and forth over the same channel. This is because a movie ignores any broadcasts over any channel to which it is also listening. So we establish two one-way channels because a single channel is not two-way in practice. 17.3.4 See Also |
[ Team LiB ] |