Integrating the Communication Components

[ LiB ]  

Integrating the Communication Components

The communication components enable you to snap together a pretty sophisticated application with nearly no scripting. Although I might normally pooh pooh the bogus claim of "programming without programming," some components are hard to resist. Although I would love to document every detail of the communication components, such an exhaustive discussion is beyond the scope of this chapter. Instead, I'm including just enough information in case you plan to use them alongside your own code.

Generally, you can do all your own homemade scripting and throw in a few components and nothing will conflict. The one minor exception is how the communication components effectively overwrite key methods in your main.asc file. First, if you've succeeded in using any of the communication components, you've learned that you must create a main.asc file withat leastthe following code:


This code is effectively the same as the #include directive found in CSASit loads the modular support scripts needed for the communication components. (Alternatively, you can selectively load individual components' ASC files.)

Although you must load the component framework, you're also welcome to write your own code. However, there's one minor workaround you may need to use. Specifically, if you use application.onConnect , you can't put any code following application.acceptConnection() . Similarly, you can't put any code following application.rejectConnection() . Recall, just for one example, that you can't invoke call() on the client until the client is acceptedso it's definitely useful to have code that follows the acceptance/ rejection . The simple solution is to move all "post-acceptance" code into another callback called application.onConnectAccept (and all "post-reject" code into application.onConnectReject ). These additional callbacks shadow the connection process and will, in fact, get called at the appropriate time. You'll want the parameter in both such callbacks to mirror the onConnect . Listing 9.19 should make this clear.

Listing 9.19. Playing Nice with Component Framework
 1 load("components.asc"); 2 3 application.onConnect = function(thisClient, arg1, arg2){ 4 if(arg1=="test" && arg2=="condition"){ 5 this.acceptConnection(thisClient); 6 //put any post-accept code down in onConnectAccept 7 }else{ 8 this.rejectConnection(thisClient); 9 //put any post-reject code down in onConnectReject 10 } 11 } 12 13 application.onConnectAccept = function(thisClient, arg1, arg2){ 14 //post-accept code goes here 15 } 16 17 application.onConnectReject = function(thisClient, arg1, arg2){ 18 //post-reject code goes here 19 } 

Basically, if you put any code in line 6thinking the client was accepted by thenit won't work. Such code that you may intend to go on line 6 must not appear until line 13 (inside onConnectAccept ). The same goes for code you plan to put in line 9it needs to go down in the onConnectReject callback in line 17.


Recycling SSAS

By the way, you can build a library of reusable ASC files, save them in the common scriptlib folder, and then include them in any app using load() . You'll learn more about building a code library in Chapter 12, "Using Components."

The communication components really are useful. I think the SimpleConnect and SetBandwidth are my favorites. They're well documented, and you can find several articles on them at Incidentally, for a detailed explanation of the general framework (including the specific workaround previously discussed), check out

[ LiB ]  

Macromedia Flash MX 2004 for Rich Internet Applications
Macromedia Flash MX 2004 for Rich Internet Applications
ISBN: 0735713669
EAN: 2147483647
Year: 2002
Pages: 120 © 2008-2017.
If you may any questions please contact us: