tag:blogger.com,1999:blog-64585338292813135542023-12-29T23:06:29.087+00:00SmartFoxServer TutorIn this bog I'll post tutorials and tips about SmartFoxServer. In the client side I'll use ActionScript 2.0 for sfs1x and ActionScript 3.0 for sfs2x. In the server side I'll use ActionScript 1.0 for sfs1x and Java for sfs2x.Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-6458533829281313554.post-89607685832143450732011-08-24T14:27:00.000+01:002011-08-24T14:27:09.760+01:00SFS1X: Database Register<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hello readers! Sorry for not writing any tutorials, but... you know... lack of motivation hehe. Today I decided to write this tutorial, that for me is important for learning the basics of working with a Database.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">So, for this tutorial, I'll use the <a href="http://sfs-tutor.blogspot.com/2011/01/sfs1x-database-login.html">Database Login</a> example and add to it the Register funcionality. This time I'll improve the login flow, so it can now handle 2 zones: 1 for the login and the other for the register.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<b><span class="Apple-style-span" style="color: #cc0000; font-family: Arial, Helvetica, sans-serif; font-size: large;">::::: The Client Side (1/2) :::::</span></b><br />
<b><span class="Apple-style-span" style="color: #cc0000; font-family: Arial, Helvetica, sans-serif;"><br />
</span></b><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">First open the Fla file, go to the Library (Ctrl + L on Windows) and duplicate the Login button Symbol. To do that, Right-Click on it and press "Duplicate..." (or "Duplicate Symbol...") and put "Register button" without the quotes as the new Symbol name. Then drag the newly created Symbol to the stage and put it on the side of the Login button (like in the picture below). Finally, edit the Register button and change its label to "Register" without the quotes and give it the instance name of "register_btn".</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwukWrBMq0TPDVb5FI5w7IuWkk6MqgvAZbLBRHO8j7s198M5yEOMXedgA83k5vJVWqYTRWu1zeotC6aOhhop1p2nM-FXhe1Bh7V6mW4FxnHPIoPgVZRhfYsWZQbp0uwuqR0R5H8gUpup6Z/s1600/img1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><img border="0" height="115" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwukWrBMq0TPDVb5FI5w7IuWkk6MqgvAZbLBRHO8j7s198M5yEOMXedgA83k5vJVWqYTRWu1zeotC6aOhhop1p2nM-FXhe1Bh7V6mW4FxnHPIoPgVZRhfYsWZQbp0uwuqR0R5H8gUpup6Z/s320/img1.png" width="320" /></span></a></div><div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now we need to create the Register Window. So, draw a simple rectangle, add an Username, Password, Email and Error textfields and input textfields and add the Register button at the bottom. If you want you want you can also add a Cancel Button, like I did below. Then add the following instance names:</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Username:</b> userName;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Password:</b> passWord;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Email:</b> email</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Error:</b> error</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Register button:</b> register_btn</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Cancel button:</b> cancel_btn</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Finally, select all the design and convert it to a MovieClip (right click then Convert to Symbol, select Movieclip as the type and give it the name of RegisterWndow - for example) and, in the Advanced section of the New Symbol window, select Export for ActionScript, Export in first frame and then put "registerWindow" in the Identifier field. Then delete the Register window from the stage and you're done.</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtLw-kVPtoj23FuqeNaexLXGt65eV0VVsscWo1eW9_XvUa6Eq4Qx5jZVGNfOyxnmS9nCcLFU1f5ndyjHfLsW0PCoVveRhDTCy2grgeHB3zZHJmjld7tG22tD5eiFOED_xbHkNfgbOjwzec/s1600/img2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><img border="0" height="154" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtLw-kVPtoj23FuqeNaexLXGt65eV0VVsscWo1eW9_XvUa6Eq4Qx5jZVGNfOyxnmS9nCcLFU1f5ndyjHfLsW0PCoVveRhDTCy2grgeHB3zZHJmjld7tG22tD5eiFOED_xbHkNfgbOjwzec/s320/img2.png" width="320" /></span></a></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="color: lime; font-family: Arial, Helvetica, sans-serif;"><b>[Optional]</b></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">If you want to also create a shadow that stays behind the window and prevents the user from clicking outside it, you can simply create a black square, with alpha around 50% and with width and height equal as the stage size (see the image below). Then you convert it to a new Movieclip, give it the name you want (for example disabler) and add it to the stage, in a new layer, above the Layer 1. Don't forget to give it an instance name, like for example "disabler". Finally, put it at the position x=0 and y=0. You also need to add the following line in the disabler's first frame's actions: this._visible = false;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh094A4nVDSsbb0bNoxZfzMLsCrsgBXek4DqVPF0L07flMKdrPnEdwZQYOIuEnw4Oo8KQMJsd_ie40SSVaOJtOO3ReUc2R_BikJJw415vneCu1qWeoViTP3Cgn6QiIb0L3zVypaw3sLy7k0/s1600/img3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh094A4nVDSsbb0bNoxZfzMLsCrsgBXek4DqVPF0L07flMKdrPnEdwZQYOIuEnw4Oo8KQMJsd_ie40SSVaOJtOO3ReUc2R_BikJJw415vneCu1qWeoViTP3Cgn6QiIb0L3zVypaw3sLy7k0/s320/img3.png" width="216" /></span></a></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Now the coding part.</b></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">To handle the newly created window and other windows we may add in the future, we create 2 simple functions: showWindow and hideWindow:</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">var stageW:Number = 220;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">var stageH:Number = 150;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">function showWindow(linkageName:String):MovieClip</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">{</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>disabler._visible = true</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-tab-span" style="font-family: Arial, Helvetica, sans-serif; white-space: pre;"> </span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var window = _root.attachMovie(linkageName, linkageName, 9999)</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-tab-span" style="font-family: Arial, Helvetica, sans-serif; white-space: pre;"> </span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>window._x = (stageW / 2) - (win._width / 2)</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>window._y = (stageH / 2) - (win._height / 2)</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-tab-span" style="font-family: Arial, Helvetica, sans-serif; white-space: pre;"> </span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return win</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">function hideWindow(windowName:String)</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">{</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>this[windowName].removeMovieClip()</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>disabler._visible = false</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">As you can see, at the beginning we create 2 properties: stageW - which is the width of the stage, and stageH - which is the height of the stage. These values will be used in the showWindow function, for centering the window at the middle of the stage. Note: we don't use the stage._width and stage._height because these values aren't always correct, and as the stage never changes, so we use our own values.</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The showWindow and hideWindow functions are really simple, they just create or remove a new movieclip with the provided linkage name (which is the name that we entered in the Identifier field, on the Advanced panel of the New Symbol window).</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now that we have our Window Manager done, we can continue and put the register and cancel button working. So, on the first frame of the stage, edit the following (in bold):</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">userName._visible = false;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">passWord._visible = false;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">login_btn._visible = false;</span></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">register_btn._visible = false;</span></b></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">...</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">smartfox.onConnection = function(success) {</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (success) {</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>...</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>login_btn._visible = true;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>login_btn.onRelease = sendLogin;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><b>register_btn._visible = true;</b></span></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>register_btn.onRelease = openRegister;</span></b></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>...</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">function openRegister(){</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>showWindow("registerWindow")</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></b></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">...</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">smartfox.onConnectionLost = function() {</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>...</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>userName._visible = false;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>passWord._visible = false;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><b>register_btn._visible = false;</b></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">};</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">If you test right now, you can open the Register window, but you can't do much more than that. So let's go now to the Register window's code:</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Selection.setFocus("userName")</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">function closeMe(){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_root.hideWindow(_name)</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">function sendRegister(){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(userName.text != ""){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(passWord.text != ""){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(email.text != ""){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_root.task = "register";</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_root.registerObj = {uName:userName.text, pass:passWord.text, email:email.text};</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(_root.connected){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>error.text = "Registering..."</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_root.smartfox.login(_root.registerZone, "", "");</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else{</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>error.text = "Connecting..."</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_root.connect();</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else{</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>error.text = "Please enter your Email."</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else{</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>error.text = "Please enter your Password."</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else{</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>error.text = "Please enter your Username."</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("error")</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">register_btn.onRelease = sendRegister;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">cancel_btn.onRelease = closeMe;</span></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">So we added a closeMe function, that will be called by the cancel_btn, which will simply... well... close/hide the registerWindow. The sendRegister function is a simple function that simply detects if the user has written anything in all the fields, and then sets the task variable (which will be used to differentiate each flow) to "register" and prepares the register object which will be sent to the extension upon register time and then logs in the registerZone (which name I've stored in a variable called registerZone) with empty user and password (we need to login to send extension requests, thats why we here log in with empty username and password, or as a guest if you prefer) or connects in case it lost the connection with the server.</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">To finish the 1st part of the client side, now we only need to do some more changes to the first frame of the main stage (new code in bold black, deleted code in bold red):</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">...</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">var ip:String = "127.0.0.1";</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">var port:Number = 9339;</span></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="color: red; font-family: Arial, Helvetica, sans-serif;">var zone:String = "TutorZone";</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">var loginZone:String = "TutorZone";</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">var registerZone:String = "TutorZone2";</span></b></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">var connected:Boolean = false;</span></div><div class="separator" style="clear: both; font-weight: bold; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">var task = "";</span></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">...</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">smartfox.onConnection = function(success) {</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (success) {</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>...</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><b>if(task == "login"){</b></span></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>smartfox.login(loginZone,userName.text,passWord.text);</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else if(task == "register"){</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>smartfox.login(registerZone,"","");</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else if(task == ""){</span></b></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b><span class="Apple-style-span" style="font-weight: normal;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span></b></span></b><b><span class="Apple-tab-span" style="white-space: pre;"> </span></b><span class="Apple-tab-span" style="white-space: pre;"><b> </b>userName._visible = true;</span></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b><span class="Apple-style-span" style="font-weight: normal;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span></b></span></b><b><span class="Apple-style-span" style="font-weight: normal;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span></b></span></b><span class="Apple-tab-span" style="font-weight: bold; white-space: pre;"> </span>...</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>Selection.setFocus(userName);</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><b>}</b></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">function sendLogin() {</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><b>task = "login"</b></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (connected) {</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (userName.text != "") {</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>...</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><b><span class="Apple-style-span" style="color: red;">smartfox.login(zone,userName.text,passWord.text);</span></b></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><b>smartfox.login(loginZone,userName.text,passWord.text);</b></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>...</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">...</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">smartfox.onExtensionResponse = function(resObj:Object) {</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>...</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">};</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">smartfox.onLogin = function(resObj:Object){</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(task == "register"){</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(resObj.success){</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_root["registerWindow"].error.text = "Joining Room...";</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else{</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_root["registerWindow"].error.text = resObj.error;</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></b></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">smartfox.onRoomListUpdate = function(roomList:Object) {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><b>if(task == "login"){</b></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>gotoAndStop("lobby");</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>display.text = "Logged in as "+_global.myName;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><b>}else if(task == "register"){</b></span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>smartfox.autoJoin();</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></b><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">};</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">smartfox.onJoinRoom = function(r:Room){</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(task == "register"){</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_root["registerWindow"].error.text = "Registering...";</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>smartfox.sendXtMessage("DatabaseRegisterExt", "register", _root.registerObj)</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></b><br />
<br />
<div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">As you see, we only made some minor changes to support the task variable. But why did we add the smartfox.onLogin handler if we already handle the extension response which is who is handling the login (because we're using customLogin)? Well, because in the register zone, we don't need customLogin, as it is a waste of time and resources, because we only need to enter the server to be able to communicate with the Register extension. </span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Please note that you can only interact with extensions only after joining a room, so that's why we use the smartfox.autoJoin() (which joins automatically the room that has the autoJoin property set to true) and only send the extension request after a successful join. </span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">And that's all for now.</span></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="color: #cc0000; font-family: Arial, Helvetica, sans-serif; font-size: large;">::::: The Server Side :::::</span></b></div><div class="separator" style="clear: both; text-align: left;"><b><span class="Apple-style-span" style="color: #cc0000; font-family: Arial, Helvetica, sans-serif;"><br />
</span></b></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Finally the server-side... lets get directly to action!</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">So here's the <b>DatabaseRegisterExt.as</b> code:</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">var dbase</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">function init(){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>dbase = _server.getDatabaseManager()</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">function destroy(){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>delete dbase</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">function handleInternalEvent(evt){ //not used }</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">function handleRequest(cmd, params, user, fromRoom){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (cmd == "register") {</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("starting registration proccess")</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var userName = params.uName;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var passWord = params.pass;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var email = params.email;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var response = {_cmd:cmd };</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var error = "";</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var success = false;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var sql = "SELECT COUNT (NAME) FROM USERS WHERE NAME='"+_server.escapeQuotes(userName)+"'";</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var queryRes = dbase.executeQuery(sql)</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (queryRes != null){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var Row = queryRes.get(0)</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var count = Row.getItem("COUNT(NAME)");</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(count == 0){</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("USERNAME NOT REGISTERED, REGISTERING");</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sql = "INSERT INTO USERS (NAME, PASS, EMAIL) VALUES ('" + userName + "', '" + passWord + "', '" + email + "')";</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>queryRes = dbase.executeCommand(sql);</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>success = true;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else{</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("USERNAME ALREADY REGISTERED!")</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>error = "The username entered is already registered.";</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else{</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>error = "Error connecting to the database";</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>response.error = error;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>response.success = success;</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_server.sendResponse(response, -1, null, [user])</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">}</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">As you see, this time we used the handleRequest instead of the handleInternalEvent, as the handleRequest handles client requests when the handleInternalEvent only handles server events like user login, user logout, etc.</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">In the handleRequest function, the cmd parameter is the command sent by the user, the params object is the extra data that the user sends, the user parameter is the user who sent the request and the fromRoom is the id of the room from where the request was originated. It is very similar to the smartfox.sendXtMessage(), in terms of parameters, so you shouldn't have problems with it.</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Before we register the user (by using the INSERT INTO SQL command) we first check if there is already registered an user with the same username, and the COUNT() sql function retrieves the number of rows found that meet the provided condition.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Another difference is that this time we use the executeCommand instead of the executeQuery, because the executeQuery is just used for returning queries (like SELECT, COUNT, etc) while the executeCommand updates the database (you use it for everything that changes the database's data, like INSERT INTO, DROP, etc).</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<b><span class="Apple-style-span" style="color: #cc0000; font-family: Arial, Helvetica, sans-serif; font-size: large;">::::: The Client Side (2/2) :::::</span></b><br />
<b><span class="Apple-style-span" style="color: #cc0000; font-family: Arial, Helvetica, sans-serif;"><br />
</span></b><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The final step is handling the response of the register extension, so we just need to update the onExtensionResponse function:</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">smartfox.onExtensionResponse = function(resObj:Object) {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (resObj._cmd == "logOK") {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_global.myName = resObj.name;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>smartfox.getRoomList();</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>} else if (resObj._cmd == "logKO") {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>error.text = "Error at login: "+resObj.error;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>status.text = "Connected";</span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else if(resObj._cmd == "register"){</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("register response")</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(resObj.success){</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("success")</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_root["registerWindow"].error.text = "Register successful";</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}else{</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("error")</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_root["registerWindow"].error.text = resObj.error;</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></b><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></b><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">};</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<b><span class="Apple-style-span" style="color: #cc0000; font-family: Arial, Helvetica, sans-serif; font-size: large;">::::: Conclusion :::::</span></b><br />
<b><span class="Apple-style-span" style="color: #cc0000; font-family: Arial, Helvetica, sans-serif; font-size: large;"><br />
</span></b><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hope you liked this tutorial :-)! I don't know if this means my temporary return or not, who knows. I'll post the tutorial's source later. </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Cya next time, and happy coding! ;-)</span><br />
Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com7tag:blogger.com,1999:blog-6458533829281313554.post-13392477525972953842011-03-25T13:35:00.000+00:002011-03-25T13:35:45.797+00:00BLOG: Current Situation<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hello readers! Im really sorry for not writing any new tutorials, but the reason for that is that I've been really really busy with tests and school and don't have any free time. So this blog will become a seasonal blog, and will only get updated at Easter, Summer and Christmas holidays. See you soon!</span>Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com2tag:blogger.com,1999:blog-6458533829281313554.post-92066465950519370182011-01-07T17:09:00.006+00:002011-08-24T12:54:26.369+01:00SFS1X: Database Login<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hi there! In this tutorial I'll explain how can you make a simple Flash Application that connects and then logs in, after the server verifies the credentials to check if there is a user registered with those credentials. This tutorial will be based in the <a href="http://sfs-tutor.blogspot.com/2011/01/sfs1x-simple-login.html" target="_blank">Simple Login Tutorial</a>, so I suggest you to do it <b>before</b> doing this.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">For making the Database Login, I'll use:</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">- H2 Database as the database that will store the registered user's information;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">- An AS1.0 Extension, that will handle the <b>login process</b>;</span><br />
<br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">You can download the source code of this tutorial <a href="http://depositfiles.com/files/i30f2jwzg" target="_blank">here</a>.</span></b><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">So, the <b>Client Side</b></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">First open the Fla file that you created in the <a href="http://sfs-tutor.blogspot.com/2011/01/sfs1x-simple-login.html" target="_blank">Simple Login Tutorial</a>.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">You'll need to create a <b>new Input TextField</b> after the <b>userName </b><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">(using the</span><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"> </span><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><b>Text Tool</b></span><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">, shortcut key:</span><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"> </span><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><b>T</b></span><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">) </span><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">and give it the <b>Instance Name</b> "<b>passWord</b>" without the quotes and set its Behavior property to <b>Password </b>(</span><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><b>Like the following image</b></span><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">).</span></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCLNR6OqR6pjYvaudvX29tw22TrnAYCPdF0TsUgGt9VIqcs7n4AjOm6gUbPsx8zkQAuaT52OzMV9mDkMmbTyLR7AjizdWl9P-joFzMHRG_op_VfRWBKSRw-H0qhdIE5QqUE-52VuRFA2zv/s1600/Image2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="color: black;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCLNR6OqR6pjYvaudvX29tw22TrnAYCPdF0TsUgGt9VIqcs7n4AjOm6gUbPsx8zkQAuaT52OzMV9mDkMmbTyLR7AjizdWl9P-joFzMHRG_op_VfRWBKSRw-H0qhdIE5QqUE-52VuRFA2zv/s1600/Image2.jpg" /></span></a></div><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">You can optionally add a <b>new Dynamic TextField</b> after the <b>userName</b> and give it the Instance Name "<b>errorMsg</b>" without the quotes. This TextField will show the common login errors like "Username or password wrong", "can't connect to the database", etc.</span></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">Finally you need to edit some of the code that is in the first frame, so it will stay like this:</span></span><br />
<pre class="brush: as3">import it.gotoandplay.smartfoxserver.*;
stop();
var ip:String = "127.0.0.1";
var port:Number = 9339;
var zone:String = "TutorZone";
var connected:Boolean = false;
userName._visible = false;
passWord._visible = false;
login_btn._visible = false;
var smartfox:SmartFoxClient = new SmartFoxClient();
smartfox.debug = true;
connect();
function connect() {
status.text = "Connecting";
smartfox.connect(ip,port);
}
smartfox.onConnection = function(success) {
if (success) {
status.text = "Successfully connected!";
connected = true;
userName._visible = true;
passWord._visible = true;
login_btn._visible = true;
login_btn.onRelease = sendLogin;
Selection.setFocus(userName);
} else {
status.text = "Can't connect!";
}
};
function sendLogin() {
if (connected) {
if (userName.text != "") {
error.text = "";
status.text = "Logging in...";
smartfox.login(zone,userName.text,passWord.text);
}
}else{
connect()
}
}
smartfox.onExtensionResponse = function(resObj:Object) {
if (resObj._cmd == "logOK") {
_global.myName = resObj.name;
smartfox.getRoomList();
} else if (resObj._cmd == "logKO") {
error.text = "Error at login: "+resObj.error;
status.text = "Connected";
}
};
smartfox.onRoomListUpdate = function(roomList:Object) {
gotoAndStop("lobby");
display.text = "Logged in as "+_global.myName;
};
smartfox.onConnectionLost = function() {
gotoAndStop("Login");
status.text = "Disconnected";
connected = false;
userName._visible = false;
passWord._visible = false;
};
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">As you can see, I changed the <b>Zone</b> to <b>TutorZone,</b> added some lines to make the </span><b style="font-size: 15px; line-height: 20px;">passWord</b><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"> TextField disappearing at the beggining and appearing when it successfully connects, like the </span><b style="font-size: 15px; line-height: 20px;">userName</b><span style="font-size: 15px; line-height: 20px;">.</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><b><span class="Apple-style-span" style="color: red;">Important Warning:</span></b> I decided to change the <b>Zone</b> not to interfere with the zones that already come with sfs and that are needed for the <b>examples</b>, and from now I'll be <b>always using the </b><b>TutorZone</b> in the next tutorials.</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">So you'll need to create a new <b>Zone</b>. If you don't know how to create a new Zone, you can follow the <a href="http://sfs-tutor.blogspot.com/2011/01/sfs1x-basic-server-configuration.html">Basic Server Configuration Tutorial</a>.</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">But there is one <b>important</b> change that I did to the script. The new <b>connect</b> function and the <b>Extension Response</b>, <b>Connection Lost </b> and <b>RoomList Update</b> <b>handlers</b>.</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><b>So let's explain this code:</b></span></span><br />
<br />
<pre class="brush: as3">function connect() {
status.text = "Connecting";
smartfox.connect(ip,port);
}
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">I only created this function so this way I can connect to the server just by executing <b>connect()</b> (or <b>_root.connect()</b> if the code is inside a movieclip) and i dont need to be always displaying the <b>status</b> and calling the <b>smartfox.connect(ip, port)</b>. I've also created a <b>connected</b> Boolean, that is true when the client <b>is connected</b> to the server and is false when the client <b>isn't</b>.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">In the <b>sendLogin</b> function, now it verifies if it is connected to the server, and if it isn't, it tries to connect to the server again.</span><br />
<pre class="brush: as3">smartfox.onExtensionResponse = function(resObj:Object) {
if (resObj._cmd == "logOK") {
_global.myName = resObj.name;
smartfox.getRoomList();
} else if (resObj._cmd == "logKO") {
error.text = "Error at login: "+resObj.error;
status.text = "Connected";
}
};
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This function handles the <b>onExtensionResponse</b> event fired by the client when it receives a response from the <b>Extension</b>. I'll talk more about the extension in the <b>Server Side</b> part of this tutorial. The <b>resObj</b> returns the data from the server. </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">In this tutorial the Extension will return the command "<b>logOK</b>" if the login succeeded or will return the command "<b>logKO</b>" if the login failed.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">If the login succeeded, I set a global variable called <b>myName</b> that will represent our <b>public name</b> (the name that everyone sees). Then it executes the <b>getRoomList()</b> command. This command is only used if the <b>customLogin</b> parameter in the <b>Zone</b> is set to <b>true</b>. If it is true, it tells the server that "<b>you don't need to handle the login, because I have an extension that will handle it for you</b>". When handling the customLogin, you need to manually request the <b>roomList</b> from the server, otherwise you won't be <b>able to join any room</b>. But if you don't have the <b>customLogin</b> set to true, in other words you aren't handling the login with an extension, you don't need to request the <b>roomList</b>, because the server automatically sends it after the <b>login</b>.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">If the login failed, it displays the error sent by the extension in the <b>error</b> TextField and displays again the "<b>Connected</b>" in the <b>status</b> TextField.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">For more information about the onExtensionResponse you can check the <b>docs</b> (</span><a href="http://www.smartfoxserver.com/docs/index.htm?http://www.smartfoxserver.com/docs/docPages/tutorials_pro/02_simpleExtension/index.htm"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">http://www.smartfoxserver.com/docs/index.htm?http://www.smartfoxserver.com/docs/docPages/tutorials_pro/02_simpleExtension/index.htm</span></a><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">) and the <b>API </b>(<a href="http://www.smartfoxserver.com/docs/docPages/as2/html/it_gotoandplay_smartfoxserver_SmartFoxClient.html#onExtensionResponse">http://www.smartfoxserver.com/docs/docPages/as2/html/it_gotoandplay_smartfoxserver_SmartFoxClient.html#onExtensionResponse</a>).</span><br />
<pre class="brush: as3">smartfox.onRoomListUpdate = function(roomList:Object) {
gotoAndStop("lobby");
display.text = "Logged in as "+_global.myName;
};
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This function handles the <b>onRoomListUpdate</b> event by the client when it receives the <b>roomList</b> from the server. In further tutorials I'll use the received <b>roomList</b>, but for now I don't need it. When it receives the <b>roomList</b>, it just goes to the <b>lobby</b> frame and displays message "Logged in as Rjgtav" for example, in the <b>display</b> TextField.</span><br />
<pre class="brush: as3">smartfox.onConnectionLost = function() {
gotoAndStop("login");
status.text = "Disconnected";
connected = false;
userName._visible = false;
passWord._visible = false;
};
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This function handles the <b>onConnectionLost</b> event fired when the client loses the connection with the server. When it loses the connection, it goes to the <b>login</b> frame (in case it is in the <b>lobby</b> frame), shows the "<b>Disconnected</b>" in the status TextField, sets the <b>connected</b> variable to <b>false</b> and hides the <b>userName</b> and <b>passWord</b> TextFields.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">We're done with the <b>Client Side</b>, now to the <b>Server Side</b>.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">First you'll need to have a database. If you don't have one, you can create one by simply doing this:</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">1. Open the <b>adminDb.bat</b> in the <b>[SmartFoxServer Installation Folder]\Server</b> (for Windows users) or run <b>./adminDb.sh</b> command in a terminal window (it will open a new browser window with the h2 login page - at least in Windows it opens).</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">2. Now enter "</span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>jdbc:h2:~/sfstutor</b></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">" without the quotes as the <b>JDBC URL</b> and enter your desired <b>User Name</b> and <b>Password</b>.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">3. Finally press the <b>Connect</b> button.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b><br />
</b></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now that you have a <b>database</b>, you need to create a <b>table</b>. For that, you just need to run this <b>SQL Statement</b> (you can run SQL statements by entering them in the big <b>central TextField</b> and by clicking the <b>Run (Ctrl+Enter)</b> button):</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">CREATE TABLE USERS(ID INT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(255), PASS VARCHAR(255), EMAIL VARCHAR(255));</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>I'll explain this code very quick:</b></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">CREATE TABLE USERS() - Creates a new table called <b>USERS</b> and its collums. The collums are set inside the <b>parentheses ()</b>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">ID INT AUTO_INCREMENT PRIMARY KEY - A collum called <b>ID</b> and type <b>INT</b>. The <b>AUTO_INCREMENT</b> will make the collum values automatically increase by 1 (like 1, 2, 3, blabla). It is the primary key of the table (you can only have one primary key per table);</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">NAME VARCHAR(255) - A collum called <b>NAME</b> and type <b>VARCHAR</b> with a maximum of <b>255</b> characters; </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">PASS VARCHAR(255) - A collum called <b>PASS</b> and type <b>VARCHAR</b> with a maximum of <b>255</b> characters;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">EMAIL VARCHAR(255) - A collum called <b>EMAIL</b> and type <b>VARCHAR</b> with a maximum of 255 characters;</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now that you have a table, you only need to do one more thing. You need to insert data, in other words <b>register users</b>, for now, I'll only explain how to do it by a SQL Statement. I'll explain how to make a register in a future tutorial. For registering the first users, you only need to run this <b>SQL Statement</b>:</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">INSERT INTO USERS (NAME, PASS, EMAIL) VALUES ('User's Username', 'User's Password', 'User's Email');</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>A quick explanation:</b></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">INSERT INTO USERS() - Inserts data into the table <b>USERS</b>. The collum's names that we are going to insert data are set inside the <b>first</b></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b> </b></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>parentheses ()</b> and the data to be inserted is set inside the </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>last </b></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>parentheses ()</b></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">;</span><br />
<br />
<span class="Apple-style-span" style="color: blue; font-family: Arial, Helvetica, sans-serif;"><b>Note:</b> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The data position inside the <b>last parentheses</b> <b>must</b> match the correspondent collum's position in the <b>first parentheses</b>.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">And you're done with the database. Now the extension.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">You need to create a <b>new Extension </b>called <b>DatabaseLoginExt</b>. If you don't know how to create an extension, you can check the <a href="http://sfs-tutor.blogspot.com/2011/01/sfs1x-simple-extension.html">Simple Extension Tutorial</a>.</span><br />
<br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This is the source code of the Extension:</span></b><br />
<br />
<pre class="brush: as3">var dbase
var userName;
var passWord;
var SocketChannel;
function init(){
dbase = _server.getDatabaseManager()
}
function destroy(){
delete dbase
delete userName;
delete passWord;
delete SocketChannel;
}
function handleInternalEvent(evt)
{
if(evt.name == "loginRequest"){
var error = "";
userName = evt["nick"];
passWord = evt["pass"];
SocketChannel = evt["chan"];
var sql = "SELECT COUNT (NAME) FROM USERS WHERE NAME='"+userName+"' AND PASS='"+passWord+"'";
var queryRes = dbase.executeQuery(sql)
var response = {}
if (queryRes != null){
var Row = queryRes.get(0)
var count = Row.getItem("COUNT(NAME)");
if(count == 1){
trace("SUCCESSFULL LOGIN")
var obj = _server.loginUser(userName, passWord, SocketChannel)
if(obj.success){
response._cmd = "logOK";
response.name = userName;
}else{
error = obj.error;
response._cmd = "logKO";
}
}else if(count == 0){
trace("FAILED LOGIN")
response._cmd = "logKO";
error = "Wrong username or password";
}
}else{
response._cmd = "logKO";
error = "Error connecting to the database"
}
response.error = error;
_server.sendResponse(response, -1, null, SocketChannel)
}
}
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Here's the explanation of the Extension code:</b></span><br />
<br />
<pre class="brush: as3">function init(){
dbase = _server.getDatabaseManager()
}</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This function handles the <b>init</b> event. When the Extension <b>inits</b>, it sets the <b>dbase</b> variable as the Zone's <b>Database Manager</b>.</span><br />
<pre class="brush: as3">function destroy(){
delete dbase
delete userName;
delete passWord;
delete SocketChannel;
}
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This function handles the <b>destroy </b>event. When the Extension is <b>destroyed</b>, it <b>deletes</b> all the used variables.</span><br />
<pre class="brush: as3">if(evt.name == "loginRequest"){
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Checks if the event received is the loginRequest (the one that is sent when the client is requesting to login).</span><br />
<pre class="brush: as3">userName = evt["nick"];
passWord = evt["pass"];
SocketChannel = evt["chan"];
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The <b>evt</b> param received from the <b>loginRequest</b> event, is an <b>Object</b>. So we are setting the <b>variables</b> to the correspondent data in the evt Object.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b><span class="Apple-style-span" style="color: blue;">Note:</span></b> It could be evt.nick instead of evt["nick"]. It's the same</span><br />
<pre class="brush: as3">var sql = "SELECT COUNT (NAME) FROM USERS WHERE NAME='"+userName+"' AND PASS='"+passWord+"'";
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This code sets the <b>sql</b> variable. It is a <b>prepared statement</b>. This prepared statement counts the number of users in the database that have the received<b> userName</b> and <b>passWord</b>.</span><br />
<pre class="brush: as3">var queryRes = dbase.executeQuery(sql)
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This code makes the <b>Database Manager</b> execute the Prepared Statement <b>sql</b> and sets the <b>queryRes</b> variable as the <b>result</b> returned from the query. There are two commands to execute a SQL Statement. The <b>executeQuery()</b> and the <b>executeUpdate()</b>. The difference between them is that the executeQuery() only <b>queries</b> the database, in other words, gets data from it and the executeUpdate() only <b>updates</b> the database, for example, insert new data.</span><br />
<pre class="brush: as3">var response = {}
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Creates a new Object. The response Object will be sent to the client (<b>ExtensionResponse</b> event).</span><br />
<pre class="brush: as3">var Row = queryRes.get(0)
var count = Row.getItem("COUNT(NAME)");
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The <b>queryRes</b> object is the <b>result</b> returned from the query and the result is made of rows. As the database won't have duplicated users, the result will only return a maximum of <b>one row</b>, and as the queryRes is an <b>Array</b>, we get its first parameter (the 0). The Row has items (corresponding to the <b>collums</b>), and when we do a <b>SELECT COUNT()</b>, it only returns a collum called <b>COUNT(the name of the collum to count)</b>. So we get that item and assign it to the count variable.</span><br />
<pre class="brush: as3">var obj = _server.loginUser(userName, passWord, SocketChannel)
if(obj.success){
response._cmd = "logOK";
response.name = userName;
}else{
error = obj.error;
response._cmd = "logKO";
}
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">If the count equals 1, than that means that there's a registered user with the entered credentials, so we login it and assign a variable to the loginUser function, that will be the return of the function. If it returns true, it means that the user successfully logged in. If it returns false, it means that it failed during the log in proccess. Then we set the _cmd of the response. This property is like the name of the result from the ExtensionRequest sent by the client. In this case, we set it as "logOK" if the login succeeded and "logKO" if the login failed. And if the login failed, we assign the error to a variable, that will be returned inside the response Object.</span><br />
<pre class="brush: as3">response.error = error;
_server.sendResponse(response, -1, null, SocketChannel)
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">In this code we set the error property inside the response Object as the error (As you can see along the code I set some more errors). Then we send the response back to the client. For more information about the <b>sendResponse()</b> function you can check the <b>ServerSide API </b>(<a href="http://www.smartfoxserver.com/docs/docPages/serverSideApi/_server/sendResponse.htm">http://www.smartfoxserver.com/docs/docPages/serverSideApi/_server/sendResponse.htm</a>)</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now, all you need to do is to modify your Zone in the config.xml, so it will stay like this:</span><br />
<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><Zone name="TutorZone" uCountUpdate="true" maxUsers="10000" customLogin="true" roomListVars="true"></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <AutoReloadExtensions>true</AutoReloadExtensions></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <Rooms></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <Room name="Login" maxUsers="5000" autoJoin="true" limbo="true" /></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><Room name="Lobby" maxUsers="5000" isPrivate="false" isTemp="false" autoJoin="false" uCountUpdate="true" extensionName=""/></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></Rooms></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><DatabaseManager active="true"></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><Driver>sun.jdbc.odbc.JdbcOdbcDriver</Driver></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><ConnectionString>jdbc:h2:~/sfstutor</ConnectionString></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><UserName><b>Your database's UserName</b></UserName></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><Password><b>Your Database's Password</b></Password></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><TestSQL><![CDATA[SELECT COUNT(*) FROM USERS]]></TestSQL></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><MaxActive>100</MaxActive></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><MaxIdle>100</MaxIdle></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><OnExhaustedPool>fail</OnExhaustedPool></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><BlockTime>5000</BlockTime> </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span></DatabaseManager></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </span><Extensions></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><extension name="LoginExt" className="DatabaseLoginExt.as" type="script" /></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span></Extensions></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"></Zone></span><br />
<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">For more information about how to create a Zone you can check the <span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><a href="http://sfs-tutor.blogspot.com/2011/01/sfs1x-basic-server-configuration.html">Basic Server Configuration Tutorial</a></span><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">.</span></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: blue; font-size: 15px; line-height: 20px;"><b>Tip:</b></span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;"> Don't forget to set the <b>Local playback security</b> to <b>Access network only</b>. For more information about this, you can check <a href="http://sfs-tutor.blogspot.com/2011/01/tip-adobe-flash-player-security-error.html">this</a> tip.</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">You can download the source code of this tutorial <a href="http://depositfiles.com/files/i30f2jwzg" target="_blank">here</a>.</span></b><br />
<br />
<br />
<div style="color: black; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;">And that's all. I hope you enjoyed this tutorial. If you have any questions, fell free to ask me (by commenting or by dropping me a pm in the sfs forums).</span></span></div><div style="color: black; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;"><br />
</span></span></div><div style="color: black; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;">Stay tuned for the next tutorial ;-)</span></span></div></div>Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com28tag:blogger.com,1999:blog-6458533829281313554.post-57998880195971678992011-01-07T15:46:00.003+00:002011-01-07T17:09:01.343+00:00SFS1X: Simple Extension<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hi. In this tutorial I'll explain how to make the most Simple Extension, most known as "Hello World" Extension.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: blue;"><b>Importat Note:</b></span> This is a Zone Level Extension, so it's attached to a Zone. There are the Room Level Extensions too, but the only difference is that they're attached to a Room instead.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">An <b>Extension</b>, as the name says, is a way to <b>extend the server functionalities</b>. It has many uses like handling the <b>Login proccess</b> (by verifying the credentials in a database), handling a game (like the score of each player in the game) and any other things.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">So let's begin the tutorial!</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">First you need to create a <b>new ActionScript File</b>. Then you only need to put there this code:</span><br />
<pre class="brush: as3">function init()
{
trace("Hello World!")
}
function destroy(){
trace("Bye World!")
}
function handleRequest(cmd, params, user, fromRoom){
trace("Request Received from: "+user.getName())
}
function handleInternalEvent(evt){
trace("Event received: "+evt.name)
}
</pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">As you can see, the <b>Extension</b> has only this functions (plus the <b>handleRequest</b> function) to handle the server events. </span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The <b>init</b> function handles the init event that is fired when the extension is inited (after the Zone is inited). In this case, we only display the "Hello World!" message, that can be checked in the console, after the correspondent Zone is inited.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The <b>destroy</b> function handles the destroy event that is fired when the extension is destroyed. In this case, we only display the "Bye World!" message, that can be checked in the console.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The <b>handleInternalEvent</b> function handles all the internal events that are fired, like userJoin, userExit, etc. In this case we only display the name of the event received. </span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The <b>handleRequest</b> function handles the request event sent by the client (with the <b>sendXtMessage</b>). </span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now you only need to <b>deploy</b> the Extension. To do that, you need to copy you ActionScript File to the </span><span class="Apple-style-span" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;"><b>[SmartFoxServer Installation Folder]\Server\sfsExtensions</b> folder, then you need to add your Extension to the Zone where you want to place it. For that you need to enter the following code, in the <b><Extensions></b> block that is in your <b>Zone block</b>. So it will stay like this:</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><Zone name="Your Zone" blablablabla></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> bla</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="white-space: normal;"> bla</span></span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="white-space: normal;"><span class="Apple-tab-span" style="white-space: pre;"><span class="Apple-style-span" style="white-space: normal;"> bla</span></span></span></span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <Extensions></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> <extension name="MostSimpleExtension" className="MostSimpleExtension.as" type="script" /></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> </Extensions></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"></Zone></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The extension configuration has the following parameters:</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>name</b> - Is a name that will be used to refer to the Extension. Used in the <b>sendXtMessage(extensionName, blablabla)</b></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>className</b> - Is the name of the ActionScript File of the Extension.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>type</b> - Is the type of the extension. As it is an ActionScript extension, its type is <b>script</b>. If it was a Java Extension, its type would be <b>java</b>.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">After this, you only need to start your Server.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;">And that's all. I hope you enjoyed this tutorial. If you have any questions, fell free to ask me (by commenting or by dropping me a pm in the sfs forums).</span></span>Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com0tag:blogger.com,1999:blog-6458533829281313554.post-87152991541292192082011-01-07T14:22:00.001+00:002011-01-07T17:09:01.343+00:00SFS1X: Basic Server Configuration<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hi. This tutorial isn't finished yet. I'll update it as I need in my future tutorials. So let's begin!</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Zone</b></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">A Zone is like an application (like a game, a chat, etc.) or a group of rooms, if you prefer, and each room has its players that can join all the rooms inside the zone where they are. You can create a new Zone <b>only</b> by editing the <b>config.xml </b>under </span><span class="Apple-style-span" style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;"><b>[SmartFoxServer Installation Folder]\Server</b> </span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">(with any text editor like notepad)</span></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">To create a new zone, you only need to add this code before the <b><Zones></b> section. (Each zone is defined by a <b><Zone></b> block)</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><Zone name="ZoneName" uCountUpdate="true" maxUsers="200" customLogin="false"></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"></Zone></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This is a simple Zone. Of course there are much more parameters to set in the Zone like for example <b>roomListVars</b>, that sets if the rooms can have or not <b>Room Variables</b>. Here's an explanation about the above parameters:</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">name - is the name of the Zone</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">uCountUpdate - if set to <b>true</b>, it sends to the clients an <b>userCountUpdate</b> event when the number of players/users in a room changes.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">maxUsers - sets the maximum amount of users that the Zone will handle</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">customLogin - if set to false, the server handles the <b>login proccess</b>, but if set to true, the server doesn't handle the login process. When it receives the login request from the client, it redirects it for the<b> Zone Extension</b>, that will handle the <b>login proccess</b>.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This is just the first part of the configuration of a <b>Zone</b>. You need also to configure the default <b>Rooms</b> that will be always in the <b>Zone</b> and there are many other things to configure like the <b>buddyList</b> (optional), the <b>Database Manager</b> (optional), the <b>Extensions</b> (optional), <b>Moderators</b> (optional), etc.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b>Database Manager</b></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">To configure the Database Manager, you need to add this code in the Zone where you want to add it.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><DatabaseManager active="true"></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="white-space: pre;"> </span><Driver>The Driver</Driver></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="white-space: pre;"> </span></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; white-space: pre;"> </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><ConnectionString>The URL</ConnectionString></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="white-space: pre;"> </span><UserName>Database Username</UserName></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="white-space: pre;"> </span><Password>Database Password</Password></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="white-space: pre;"> </span><TestSQL><![CDATA[Test SQL Statement]]></TestSQL></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="white-space: pre;"> </span><MaxActive>100</MaxActive></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="white-space: pre;"> </span><MaxIdle>100</MaxIdle></span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; white-space: pre;"> </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="white-space: pre;"> </span><OnExhaustedPool>fail</OnExhaustedPool></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="white-space: pre;"> </span><BlockTime>5000</BlockTime> </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"></DatabaseManager></span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">I think I don't need to explain the paremeters of the Database Manager, as its names tell everything.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">I'll explain the of this parameters later.</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">For more information about the Basic Configuration, you can check the docs (<a href="http://www.smartfoxserver.com/docs/index.htm?http://www.smartfoxserver.com/docs/docPages/config/basics.htm#zone" target="_blank">http://www.smartfoxserver.com/docs/index.htm?http://www.smartfoxserver.com/docs/docPages/config/basics.htm</a>)</span><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Stay tuned for updates ;-)</span>Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com0tag:blogger.com,1999:blog-6458533829281313554.post-62009933158513449252011-01-04T19:38:00.004+00:002011-01-07T17:09:16.181+00:00TIP: Adobe Flash Player Security Error<span class="Apple-style-span" style="font-family: inherit;">Hi. When you're developing your Flash applications, sometimes you will need to open the <b>swf</b> file of your app, and you may enounter this warning:</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaaAG6TsK8Q6RMEIFAB7ZN-k-W0q6yqg-FU_kZoBn_AaAijyX41hKRyWRMo722vHglrI0nYYNjz9D0hDqjI7ifZx6I7xkMGvVFI4Vxu2k1gg1k1ZaSFU2p1ykWIJZALMrDvQyBBWntjK7_/s1600/Potentially+Unsafe+Operation.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaaAG6TsK8Q6RMEIFAB7ZN-k-W0q6yqg-FU_kZoBn_AaAijyX41hKRyWRMo722vHglrI0nYYNjz9D0hDqjI7ifZx6I7xkMGvVFI4Vxu2k1gg1k1ZaSFU2p1ykWIJZALMrDvQyBBWntjK7_/s1600/Potentially+Unsafe+Operation.jpg" /></span></a></div><span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">If you get this warning, your swf file will <b>not connect</b> to your server or to the url you're trying to connect.</span><br />
<span class="Apple-style-span" style="font-family: inherit;">To prevent this, you only need to set the <b>Local playback security</b> in the <b>Publish Settings</b> (<b>File > Publish Settings...</b>, shortcut key: <b>Ctrl+Shift+F12</b>) to <b>Access network only</b> (<b>Like the following image</b>).</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikignvjZ0VXqed2Bt15dC8MAH9N1IGcVqjptSDsf63ACyi-aMH2a0CrtxOLnr-Ho1RslHxm6M3GzqV99A3GxZKNJ5odiXKzqWokqxmZh0ZUuHx9I_5UDxIFkzE_5l6iT_shwYIVrJNZ_I3/s1600/Publish+Settings.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="font-family: inherit;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikignvjZ0VXqed2Bt15dC8MAH9N1IGcVqjptSDsf63ACyi-aMH2a0CrtxOLnr-Ho1RslHxm6M3GzqV99A3GxZKNJ5odiXKzqWokqxmZh0ZUuHx9I_5UDxIFkzE_5l6iT_shwYIVrJNZ_I3/s1600/Publish+Settings.jpg" /></span></a></div>Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com0tag:blogger.com,1999:blog-6458533829281313554.post-22757074099937562962011-01-03T20:28:00.013+00:002011-01-17T19:30:26.403+00:00SFS1X: Simple Login<span class="Apple-style-span" style="font-family: inherit;">Hello readers! In this tutorial I'll explain how to make a simple Flash application that connects and then logs in the server. I'll explain how to make a Database Login in the next tutorial.</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<b><span class="Apple-style-span" style="font-family: inherit;">You can download the source code of this tutorial <a href="http://depositfiles.com/files/yolfxi0io" target="_blank">here</a>.</span></b><br />
<b><span class="Apple-style-span" style="font-family: inherit;"><br />
</span></b><br />
<span class="Apple-style-span" style="font-family: inherit;">So, let's begin!</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">First open your Flash and create a <b>new Input TextField</b> <span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;">(using the</span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;"> </span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;"><b>Text Tool</b></span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;">, shortcut key:</span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;"> </span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;"><b>T</b></span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;">) and give it the <b>Instance Name</b> "<b>userName</b>" without the quotes and set its Behavior property to <b>Single line </b>(</span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;"><b>Like the following image</b></span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;">).</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;"><br />
</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRxZYh3qaUAnmShBQ_-7H8jUNTb6B51T2Gg6n53sEvi7GZJhv-lV9UjPJ-GUiTL8Lb1hy2Ouh7YHw6QRDnq5m3jPv24u8YXivqz_R5zyIf873q0A9EAjLaubJj3udbTELeMzvpE9fVSj96/s1600/Image1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRxZYh3qaUAnmShBQ_-7H8jUNTb6B51T2Gg6n53sEvi7GZJhv-lV9UjPJ-GUiTL8Lb1hy2Ouh7YHw6QRDnq5m3jPv24u8YXivqz_R5zyIf873q0A9EAjLaubJj3udbTELeMzvpE9fVSj96/s320/Image1.jpg" width="245" /></a></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">You can also select the <b>Show border around text</b> button (<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgByQk_SotMraKWJgJGbWz4CqqrP6ibyM9L0LRAGgxkfr0thTLAJGZuPYK4XqdUPGhP2wsBXO7S89PTjQrDNQcX8b8lVblAmEq-CnuVrJS5YUlSXNo36VBJwWOrCYO4cEMDEvWTVq7sJa_t/s1600/Show+border+around+text.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgByQk_SotMraKWJgJGbWz4CqqrP6ibyM9L0LRAGgxkfr0thTLAJGZuPYK4XqdUPGhP2wsBXO7S89PTjQrDNQcX8b8lVblAmEq-CnuVrJS5YUlSXNo36VBJwWOrCYO4cEMDEvWTVq7sJa_t/s1600/Show+border+around+text.jpg" /></a>) in the TextField. This way it will show a black border around it.</span></div><span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">Then you need to create a button. For that you first draw your button, then you convert it to a Button Symbol (<b>Right-click</b> in the button, select "<b>Convert to Symbol...</b>") and give it the <b>Instance Name</b> "<b>login_btn</b>" without the quotes (<b>Like the following image</b>).</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxEabZ2liKLdTQZvFxRc6wQDnxU9hX83xXg0emJp35y2y_xc_KLNQ1puuftVSNndmqKYxRPbzyx7EH8q955x08VrywTuSTQOhONS1JY47a-GVQj55Wkx2WgqrV5wynavMef-YbwG0M45P4/s1600/Image3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxEabZ2liKLdTQZvFxRc6wQDnxU9hX83xXg0emJp35y2y_xc_KLNQ1puuftVSNndmqKYxRPbzyx7EH8q955x08VrywTuSTQOhONS1JY47a-GVQj55Wkx2WgqrV5wynavMef-YbwG0M45P4/s1600/Image3.jpg" /></a></div><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<div class="separator" style="clear: both; text-align: center;"><span id="goog_1933901972"></span><span id="goog_1933901973"></span></div><span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">If you want, you can add the status Dynamic TextField to show the connection status. </span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">Finally add a new <b>KeyFrame</b> and give it the label "<b>lobby</b>" and add give to the first frame the label "<b>login</b>", so it looks like this:</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiftR5j8T1ED6a-WVqEHzmeHXmXcOeXPWJiO9ZdXceoMful2nrprxlWDY-T2VSnRt91DUuh3X6U4LZVAefQrIG-w0s8XfvPfwaqrrLGdkprRCgVgKZDUKMT2ZcH7yn-GnFYEg6NTNWnncYR/s1600/Image4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiftR5j8T1ED6a-WVqEHzmeHXmXcOeXPWJiO9ZdXceoMful2nrprxlWDY-T2VSnRt91DUuh3X6U4LZVAefQrIG-w0s8XfvPfwaqrrLGdkprRCgVgKZDUKMT2ZcH7yn-GnFYEg6NTNWnncYR/s1600/Image4.jpg" /></a></div><span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">In the Lobby I only put a Dynamic TextField with the Instance Name "<b>display</b>" without the quotes.</span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;">After this, you only need to add this code in the </span><span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 15px; line-height: 20px;"><b>first frame:</b></span><br />
<br />
<pre class="brush: as3">import it.gotoandplay.smartfoxserver.*
stop();
var ip:String = "127.0.0.1";
var port:Number = 9339;
var zone:String = "simpleChat";
status.text = "Connecting..."
userName._visible = false;
login_btn._visible = false;
var smartfox:SmartFoxClient = new SmartFoxClient()
smartfox.debug = true
smartfox.connect(ip, port)
smartfox.onConnection = function (success)
{
if (success)
{
status.text = "Successfully connected!"
userName._visible = true;
login_btn._visible = true;
login_btn.onRelease = sendLogin;
Selection.setFocus(userName);
}
else
{
status.text = "Can't connect!"
}
}
smartfox.onLogin = function(resObj:Object)
{
if (resObj.success)
{
gotoAndStop("lobby");
display.text = "Logged in as "+resObj.name;
}
else
{
status.text = "Error";
trace("Error Message: "+resObj.error);
}
}
function sendLogin(){
if(userName.text != ""){
status.text = "Logging in..."
smartfox.login(zone, userName.text)
}
}
</pre><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">As part of the code is from the <a href="http://sfs-tutor.blogspot.com/2011/01/sfs1x-simple-connect_02.html" target="_blank">Simple Connect Tutorial</a>, I'll only explain the new code.</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><b>So here's the explanation:</b></span></span><br />
<br />
<pre class="brush: as3">userName._visible = false;
login_btn._visible = false;
</pre><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">This simple lines of code just hide the userName TextField and the login button to prevent the user from trying to login before being connected. That's why you find this code:</span></span><br />
<br />
<pre class="brush: as3">userName._visible = true;
login_btn._visible = true;
</pre><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">When it successfully connects, to show the userName TextField and the login button again to let the user login.</span></span><br />
<br />
<pre class="brush: as3">login_btn.onRelease = sendLogin;
</pre><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">This line of code is the same as putting this code in the button:</span></span><br />
<br />
<pre class="brush: as3">on(release){
_root.sendLogin();
}
</pre><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">It calls/executes the function when the login button is clicked.</span></span><br />
<br />
<pre class="brush: as3">Selection.setFocus(userName);
</pre><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">What this line of code does is selecting the userName TextField, to facilitate the login to the user. This way the user only needs to write his/her username. For unknown reasons this code only works if you open the <b>swf</b> file or if you open it on the browser.</span></span><br />
<br />
<pre class="brush: as3">function sendLogin(){
if(userName.text != ""){
status.text = "Logging in..."
smartfox.login(zone, userName.text)
}
}
</pre><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">This function first verifies if the userName TextField is empty, and if it isn't, it sends the <b>login request</b> to the server. For further details about the <b>login</b> you can check the <b>docs</b> (<a href="http://www.smartfoxserver.com/docs/docPages/tutorials_basic/02_simpleChat_p1/index.htm" target="_blank">http://www.smartfoxserver.com/docs/docPages/tutorials_basic/02_simpleChat_p1/index.htm</a>) and the <b>AS2.0 API </b>(<a href="http://www.smartfoxserver.com/docs/docPages/as2/html/it_gotoandplay_smartfoxserver_SmartFoxClient.html#login" target="_blank">http://www.smartfoxserver.com/docs/docPages/as2/html/it_gotoandplay_smartfoxserver_SmartFoxClient.html#login</a>).</span></span><br />
<br />
<pre class="brush: as3">smartfox.onLogin = function(resObj:Object)
{
if (resObj.success)
{
gotoAndStop("lobby");
display.text = "Logged in as "+resObj.name;
}
else
{
status.text = "Error";
trace("Error Message: "+resObj.error);
}
}
</pre><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">This function handles the onLogin event, that is fired when the login successes or fails. The resObj is an object that returns when that function is called. </span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">This object has the following variables/properties:</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">- <b>success</b> Boolean that returns true when the login successes and returns false when the login fails.</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">- <b>name</b> String that is the public name that everyone sees.</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;">- <b>error</b> String that returns an error message if the login failed.</span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;">For more information about the resObj and the login process you can check the <b>AS2.0 API docs</b> (<a href="http://www.smartfoxserver.com/docs/docPages/as2/html/it_gotoandplay_smartfoxserver_SmartFoxClient.html#onLogin" target="_blank">http://www.smartfoxserver.com/docs/docPages/as2/html/it_gotoandplay_smartfoxserver_SmartFoxClient.html#onLogin</a>)</span></span><br />
<span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<span class="Apple-style-span" style="color: blue; font-family: Arial, Helvetica, sans-serif;"><b><span class="Apple-style-span" style="color: black; font-weight: normal;"><span class="Apple-style-span" style="color: blue; font-size: 15px; line-height: 20px;"><b>Tip:</b></span><span class="Apple-style-span" style="color: #333333; font-size: 15px; line-height: 20px;"> Don't forget to set the <b>Local playback security</b> to <b>Access network only</b>. For more information about this, you can check <a href="http://sfs-tutor.blogspot.com/2011/01/tip-adobe-flash-player-security-error.html">this</a> tip.</span></span></b></span><br />
<span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;"><br />
</span></span><br />
<span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;"></span></span><br />
<div style="color: black; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;"><b>You can download the source code of this tutorial <a href="http://depositfiles.com/files/yolfxi0io" target="_blank">here</a>.</b></span></span></div><div style="color: black; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;"><br />
</span></span></div><div style="color: black; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;">And that's all. I hope you enjoyed this tutorial. If you have any questions, fell free to ask me (by commenting or by dropping me a pm in the sfs forums).</span></span></div><div style="color: black; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;"><br />
</span></span></div><div style="color: black; font-size: medium; line-height: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="color: #333333;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 15px; line-height: 20px;">Stay tuned for the next tutorial (Database Login) ;-)</span></span></div></div>Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com3tag:blogger.com,1999:blog-6458533829281313554.post-50338503110832732312011-01-03T17:48:00.001+00:002011-01-03T19:44:53.290+00:00BLOG: Request a TutorialHi. From now you can request a tutorial by just commenting in the Request a Tutorial page. I hope I can find a better solution for that, but for now it works. Hope you enjoy my bog ;-)<br />
<br />
<a href="http://sfs-tutor.blogspot.com/p/request-tutorial.html">Request a Tutorial</a>Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com8tag:blogger.com,1999:blog-6458533829281313554.post-5432344650744622222011-01-02T15:08:00.013+00:002011-01-17T19:31:05.308+00:00SFS1X: Simple Connect<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hello again. In this tutorial I'll explain how to make a simple Flash application that connects to your server.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">You can download the source code of this tutorial <a href="http://depositfiles.com/files/hn0xfdmyf" target="_blank">here</a>.</span></b><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">First open your Flash and create a <b>new Flash File (ActionScript 2.0)</b>.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Create a <b>new Dynamic TextField</b> (using the <b>Text Tool</b>, shortcut key: <b>T</b>) and give it the instance name "<b>status</b>" without the quotes. (<b>Like the following image</b>)</span><br />
<br />
<div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdXg3DqtJ3mbWexGSytSvbtNqDqsP0LHulayHsUuuYbZPxKw_bZMHx0NoAptKtOlVQ07ml6GybC523703GMu6WH3BMVjXINiqEGjBbi7-Up49cytQnIAS33whubveb-ri_saaUljB8gHK-/s1600/Image1.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdXg3DqtJ3mbWexGSytSvbtNqDqsP0LHulayHsUuuYbZPxKw_bZMHx0NoAptKtOlVQ07ml6GybC523703GMu6WH3BMVjXINiqEGjBbi7-Up49cytQnIAS33whubveb-ri_saaUljB8gHK-/s1600/Image1.jpg" /></a></div><div style="text-align: center;"><br />
</div><div style="text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now the code. Add this simple code to the <b>first frame:</b></span></div><br />
<pre class="brush: as3">import it.gotoandplay.smartfoxserver.*
stop();
var ip:String = "127.0.0.1";
var port:Number = 9339;
var zone:String = "simpleChat";
status.text = "Connecting..."
var smartfox:SmartFoxClient = new SmartFoxClient()
smartfox.debug = true
smartfox.connect(ip, port)
smartfox.onConnection = function (success)
{
if (success)
{
status.text = "Successfully connected!"
}
else
{
status.text = "Can't connect!"
}
}
</pre><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Here's the explanation of the code:</span></b><br />
<br />
<pre class="brush: as3">import it.gotoandplay.smartfoxserver.*
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This line imports the SmartFoxClient class.</span><br />
<br />
<pre class="brush: as3">stop();
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This line stops the animation.</span><br />
<br />
<pre class="brush: as3">var ip:String = "127.0.0.1";
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This line sets the variable ip. This variable represents the ip of the machine where the sfs is running, that the Flash application will connect. If the sfs is running in your pc, you can let the ip as 127.0.0.1, but if the sfs isn't running in your pc or you want to publish the Flash application on the web, you need to set the ip as your external ip (the one given from <a href="http://www.whatismyip.com/" target="_blank">http://www.whatismyip.com/</a>)</span><br />
<br />
<pre class="brush: as3">var port:Number = 9339;
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This line sets the variable port. This variable represents the port where sfs is running (the one configured in the config.xml between the <serverport> and </serverport>)</span><br />
<br />
<pre class="brush: as3">var zone:String = "simpleChat";
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This line sets the variable zone. This variable represents the name of the Zone you want to connect. For further explanation about what is a Zone, please check the sfs docs (<a href="http://www.smartfoxserver.com/docs/docPages/config/basics.htm#zone" target="_blank">http://www.smartfoxserver.com/docs/docPages/config/basics.htm#zone</a>)</span><br />
<br />
<pre class="brush: as3">status.text = "Connecting..."
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This line tells the status textField to show the text "Connecting..."</span><br />
<br />
<pre class="brush: as3">var smartfox:SmartFoxClient = new SmartFoxClient()
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This line creates a new instance of the SmartFoxClient object.</span><br />
<br />
<pre class="brush: as3">smartfox.debug = true
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This line sets smartfox's debug flag to true. This way smartfox will output everything that it sends to the server and receives from it. Very useful when developing as it helps solving bugs.</span><br />
<br />
<pre class="brush: as3">smartfox.connect(ip, port)
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This line is the most important in this example. It is the one that makes the SmartFoxClient connect to the previously set ip and port.</span><br />
<br />
<pre class="brush: as3">smartfox.onConnection = function (success)
{
if (success)
{
status.text = "Successfully connected!"
}
else
{
status.text = "Can't connect!"
}
}
</pre><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This function handles the onConnection event. The onConnection event is fired when it successfully connected or when the connection timed out. It returns a boolean (success) that is true when it successfully connected and is false when it failed connect. When it successfully connects, the status textField shows "Successfully connected" but when it can't connect, it shows "Can't connect".</span><br />
<div class="separator" style="clear: both; text-align: -webkit-auto;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="separator" style="clear: both; text-align: -webkit-auto;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: blue; font-weight: bold;">Tip:</span><span class="Apple-style-span"> Don't forget to set the <b>Local playback security</b> to <b>Access network only</b>. For more information about this, you can check <a href="http://sfs-tutor.blogspot.com/2011/01/tip-adobe-flash-player-security-error.html">this</a> tip.</span></span></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">You can download the source code of this tutorial <a href="http://depositfiles.com/files/hn0xfdmyf" target="_blank">here</a>.</span></b><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">And that's all. I hope you enjoyed this tutorial. If you have any questions, fell free to ask me (by commenting or by dropping me a pm in the sfs forums).</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Stay tuned for the next tutorial ;-)</span></div>Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com1tag:blogger.com,1999:blog-6458533829281313554.post-73865198745436088422011-01-02T14:41:00.003+00:002011-01-04T19:55:42.900+00:00SFS1X: Installing the API<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hi. In this tutorial I'll teach you how do you install the API so that you can develop applications that use sfs.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">There are 2 ways to do this. The docs way and the Rjgtav's way.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">First I'll explain the docs way, that is better explained in the docs (<a href="http://www.smartfoxserver.com/docs/docPages/api/installing.htm" target="_blank">http://www.smartfoxserver.com/docs/docPages/api/installing.htm</a>)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">All you need to do is to point the classpath of your application to the location of the api of the actionscript version you're using.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">For example if you're using <b>AS2.0</b> you need to point it to <b>[SmartFoxServer Installation Folder]\Flash API\Actionscript 2.0</b></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">while if you're using <b>AS3.0</b> you need to point it to <b>[SmartFoxServer Installation Folder]\Flash API\Actionscript 3.0.</b></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">To set the classpath of your project all you need to do is click in the "<b>Settings...</b>" button in Properties panel, then click in the "<b>Settings...</b>" button on the right side of the ActionScript version and finally click in the <b>target icon button</b>. Then you only need to select one of the folders I told before.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">All of this is better explained in the docs.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now the Rjgtav's way.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">In my way, you only need to copy the ("<b>it</b>" folder for <b>AS2.0</b> or "<b>it</b>" and "<b>com</b>" folders for <b>AS3.0</b>) located under the respective folders that were previously mentioned to the folder of your project. So simple as that (at least for me it works). But I suggest you to use the one explained in the docs xD.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><b><span class="Apple-style-span" style="color: blue;">Important Note:</span></b> You only need to do this about the API in the pc where the projects are. When you upload your game to your website, you only need to upload the .swf file, because when publishing, Flash compiles all the imported API's in the .swf file, saving some work.</span>Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com0tag:blogger.com,1999:blog-6458533829281313554.post-8988448724526367362011-01-01T13:32:00.004+00:002011-01-04T19:55:58.980+00:00SFS1X: Initial Server Configuration<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Hello and welcome to the 1st tutorial of this blog. First of all, Happy New Year to everyone! Before starting the tutorial, I would like to talk a little about the blog and my objective while writing it.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">I decided to write this blog because lately in the sfs community many people has asked questions that were already answered some time ago and also because I would like to share my knowledge and experience with the SmartFoxServer and Flash.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now to the tutorial.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Today I'l explain how to initially configure the SmartFoxServer.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">First you need to download SmartFoxServer from <a href="http://www.smartfoxserver.com/products/" target="_blank">http://www.smartfoxserver.com/products/</a>.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: red;"><b>Warning:</b></span> If you're using Windows Vista/7, please install in a different folder than the Program Files one (because of the write privileges).</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Then, you need to open the port 9339 in the firewall and if you're behind a router, you need to forward that port to the internal ip of your pc. For further informations please check <a href="http://portforward.com/" target="_blank">http://portforward.com/</a></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">After this you only need to execute the file <b>start.bat</b> (for Windows users) or the by executing the command <b>./sfs start</b> (for Linux users).</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">This is better explained in <a href="http://www.smartfoxserver.com/docs/docPages/intro/installation.htm" target="_blank">http://www.smartfoxserver.com/docs/docPages/intro/installation.htm</a></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Now the configuration part.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">To configure the server you need to edit the <b>config.xml</b> file under <b>[SmartFoxServer Installation Folder]\Server</b> (You can edit it with any text editor like notepad)</span><br />
<b><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></b><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">The first parameter you need to set is the <b>ServerIP</b>. Here you set the ip you want the server to bind (your external ip given by <a href="http://whatismyip.org/" target="_blank">http://whatismyip.org/</a> or <a href="http://www.whatismyip.com/" target="_blank">http://www.whatismyip.com/</a>, it doesn't matter).</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: blue;"><b>Tip:</b> </span>If you are behind a router, i suggest you to put an <b>*</b> in the <b>ServerIP</b>. This way it will bind all the available socket addresses and you won't need to care about changing the <b>ServerIP</b> all the time anymore.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Then you need to set the <b>ServerPort</b>. Here you can set the port you want (don't forget to open it in the firewall and forward it if you're behind a router).</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-style-span" style="color: red;"><b>Warning:</b></span> The port mustn't be used by any other program/software you have. That way the server won't work and will give startup errors.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">If you want you can also configure initially the administrator login information. For that you only need to change the <b>AdminLogin</b> and <b>AdminPassword</b> parameters.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Of course you'll need to configure much more parameters (basically all of them), but this is the basic you need to put the server running.</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">For further information you can check the sfs docs (<a href="http://www.smartfoxserver.com/docs/" target="_blank">http://www.smartfoxserver.com/docs/</a>)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">If you have any questions, fell free to ask me (by commenting or by dropping me a pm in the sfs forums).</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">See you till the next tutorial ;-)</span>Rjgtavhttp://www.blogger.com/profile/05237353279804359874noreply@blogger.com0