03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The default implementation of this method performs no actions. To override the default<br />

implementation, you must assign a function containing custom actions.<br />

Parameters<br />

success:Boolean - A Boolean value indicating whether a socket connection is successfully<br />

established. If the connection succeeded, the success parameter has a value of true;<br />

otherwise the success parameter has a value of false.<br />

Example<br />

The following example illustrates the process of specifying a replacement function for the<br />

onConnect() event h<strong>and</strong>ler in a simple chat application.<br />

After creating the XMLSocket object by using the constructor method, the script defines the<br />

custom function to be executed when the onConnect() event h<strong>and</strong>ler is invoked. The<br />

function controls the screen to which users are taken, depending on whether a connection is<br />

successfully established. If the connection is successfully made, users are taken to the main<br />

chat screen on the frame labeled startChat. If the connection is not successful, users go to a<br />

screen with troubleshooting information on the frame labeled connectionFailed.<br />

var socket:XMLSocket = new XMLSocket();<br />

socket.onConnect = function (success) {<br />

if (success) {<br />

gotoAndPlay("startChat");<br />

} else {<br />

gotoAndStop("connectionFailed");<br />

}<br />

}<br />

Now that the onConnect() h<strong>and</strong>ler is defined, the connect() method is invoked to attempt to<br />

establish the connection. If the connect() method returns a value of false, the SWF file is<br />

sent directly to the frame labeled connectionFailed, <strong>and</strong> onConnect() is never invoked. If the<br />

connect() method returns true, the SWF file jumps to a frame labeled waitForConnection,<br />

which is the "Please wait" screen. The SWF file remains on the waitForConnection frame<br />

until the onConnect() h<strong>and</strong>ler is invoked, which happens at some point in the future<br />

depending on network latency.<br />

if (!socket.connect(null, 2000)) {<br />

gotoAndStop("connectionFailed");<br />

} else {<br />

gotoAndStop("waitForConnection");<br />

}<br />

See also<br />

connect (XMLSocket.connect method), Array function<br />

XMLSocket 719

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!