02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 23: Using <strong>Flash</strong> Communication Server<br />

10<br />

11 }<br />

12<br />

trace("Level: " + info.level + newline + "Code: " + info.code);<br />

13 // Event handler for Connect_Btn<br />

14 function doConnect() {<br />

15<br />

16 // If user wants <strong>to</strong> connect...<br />

17<br />

18<br />

if (Connect_btn.getLabel() == "Connect") {<br />

19 // Connect <strong>to</strong> the hello application<br />

20<br />

21<br />

client_nc.connect("rtmp:/tu<strong>to</strong>rial_hello/room_01", User.text);<br />

22 // Update but<strong>to</strong>n label<br />

23<br />

24<br />

Connect_btn.setLabel("Disconnect");<br />

25 // If user wants <strong>to</strong> disconnect...<br />

26<br />

27<br />

} else if (Connect_btn.getLabel() == "Disconnect") {<br />

28 // Close connection<br />

29<br />

30<br />

client_nc.close();<br />

31 // Reset but<strong>to</strong>n label<br />

32<br />

33<br />

Connect_btn.setLabel("Connect");<br />

34 // Reset the text fields<br />

35 user.text = "";<br />

36<br />

37<br />

message.text = "";<br />

38<br />

39 }<br />

40<br />

}<br />

41 // Callback function server calls <strong>to</strong> send message back <strong>to</strong><br />

42 // this client.<br />

43 client_nc.msgFromSrvr = function(msg) {<br />

44<br />

45 var msg;<br />

46<br />

47<br />

48 }<br />

_root.Message.text = msg;<br />

Listing 23.3<br />

Listing 23.3 shows how the message is handled using the ‘msgFromSvr’ function; the parameter<br />

passed as ‘msg’ in listing 23.2 is received by this function as the only parameter and this is then used<br />

<strong>to</strong> populate a text field. You can see this code by opening ‘tu<strong>to</strong>rial_hello.fla’ from the installed<br />

samples.<br />

373

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

Saved successfully!

Ooh no, something went wrong!