Current time: 09-10-2010, 07:56 PM Hello There, Guest! (LoginRegister)

Post Reply 
 
Thread Rating:
  • 2 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[AS3]Building an MMOCC - Part 2
Author Message
xLite Offline
Registered

Posts: 860
Joined: Apr 2008
Reputation: 13
Post: #1
[AS3]Building an MMOCC - Part 2
Welcome to part 2 of the BAM series! ColonD

In this tutorial I would like to cover the transition from timeline coding (using the Flash IDE) to pure AS3 programming using the Flex SDK with a suitable IDE (such as FlashDevelop).

Before you continue with this tutorial, it is reccomended that you are familiar with common programming techniques and perhaps know a little about Object Oriented Programming. The Flash CS3 Documentation on Programming Actionscript 3.0 will cover everything you need to know before continuing with these tutorials.

Creating Flash applications using pure AS3 code is hardly different to what you are used to (if you aren't even used to timeline coding in the Flash IDE then I would strongly consider you check out the Flash CS3 Documentation on Programming Actionscript 3.0) infact it's just a case of switching, in a sense, "wrappers". You don't need to learn an entirely different language, you just need to change the context in which you program.

For example, your "wrapper" in the Flash IDE would be a frame. All your different code, one way or another, ends up inside a frame. Now in pure AS3 programming, your "wrapper" is simply a class inside it's own text file (simply .txt files, except you change the .txt to .as). I apologise if I am over-complicating things for you, let's just get onto the coding. ColonD

Following on from the last tutorial, [AS3]Building an MMOCC - Part 1, we made a start on our project. Right now you should only have 1 file in your project and that should be the Main.as file Ignore the extra folders, for now we will focus on Main.as in the src folder.

So quickly open up your project then open the Main.as file. You should now see this:

[Image: attachment.php?aid=112]

So let's go over all this new code we are being introduced to...

Quote:package
{
}

The package keyword simply defines what folder this class is in. The src folder that Main.as currently resides in is the highest you're source code can go. However, using packages, you can organise your files into folders to make everything easier to manage. If, for example, you wanted to create a MyClass.as file and put it inside a folder called classes. You would write out the package declaration like so:

Quote:package classes
{
}

Pretty simple, right? ColonD

Quote:import flash.display.Sprite;
import flash.events.Event;

You may have come across this before, all this does is import other classes (like the one we are making now ColonD) although these havn't been made by us. These classes have been made by Adobe which let us do whatever we need to do. Like if you have used the Sprite class before, the code above simply allows the compiler to know what classes it needs to compile our code correctly. For more information on all the different types of classes you can use, check out the ActionScript 3.0 Language and Components Reference.

Quote:public class Main extends Sprite
{
}

Now this is where we define our class name, how it can be accessed and also what classes it extends. If you are unfamiliar with what I am talking about, you still have some stuff left to learn, check out the links at the top of this thread.

Quote:public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

Now this function is basically what we call the constructor. If you have no clue as to what that is, check out the links above. ColonD So what this function is basically doing is checking if the stage variable is set. If it is, it calls init();, if not, then that means the stage hasn't loaded yet. So we add an event listener to listen out for the Event.ADDED_TO_STAGE event, which is run as soon as we are able to interact with the stage.

Quote:private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
}

Finally, this is the init(); function that is called once everything is ready. All it is doing in this function is removing the event listener as we are finished with it and the line containing // entry point is where we can start writing the code for our application.


So that ends this tutorial! I really just wanted to give you a feel for what it's like to program using pure AS3. If there was anything you didn't understand, please check out the links I have posted above. Games aren't the easiest thing to program, it's all about the theory. So if you can't even use the language properly then it's just going to be too difficult for you and chances are you will just quit. Which I am sure neither of us want.

I have decided that for this series, I will be using the SmartFoxServer application as the game's server. This will mean their is less time spent on connecting to the server and security etc and more time simply making the game. If you would like to get a heads up on SmartFoxServer before-hand, check out http://www.smartfoxserver.com/. In the next tutorial we will begin on creating the actual client. So I hope you look forward to that!


To get an idea of what we will be making, you can check out my "sandbox" client. This is simply a client I use whenever I want to try out new features. It is a bit dated and won't be exactly what we are working on (I want to show you how to make something better ColonD) but it will give you a feel of what you can expect to accomplish. So to have a look, pay a visit to http://www.calumscott.com/castiel/engine/.


As usual, please leave feedback on the tutorial, let me know if there is anything else that should be included etc etc. Also a little rep wouldn't hurt either Imawesome


EDIT: Part 3 is complete! Check it out at http://mmoccforum.com/showthread.php?tid=17964

[Image: 0a232ed4862b3be39b47dd42f2fd57ba.gif]
The Ultimate Battle... who will win?
(This post was last modified: 07-30-2010 05:49 PM by xLite.)
05-22-2010 07:01 AM
Visit this user's website Find all posts by this user Quote this message in a reply
LabRat Offline
Registered

Posts: 54
Joined: Feb 2010
Reputation: 0
Post: #2
RE: [AS3]Building an MMOCC - Part 2
Great work Calum +rep Hope you keep it up and don't die before you finish this.

[Image: nwacd0.png][Image: 8184433f3860e146a09a9769910c836cmilips_logo.png]
05-22-2010 07:19 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Willy Offline
Administrators

Posts: 4,038
Joined: Oct 2007
Reputation: 5
Post: #3
RE: [AS3]Building an MMOCC - Part 2
[approved]

Keep it up. Happybracket

born to ride
05-22-2010 02:57 PM
Find all posts by this user Quote this message in a reply
lewisfroom Offline
Registered

Posts: 168
Joined: Nov 2008
Reputation: -2
Post: #4
RE: [AS3]Building an MMOCC - Part 2
Thanks for this tutorial and the links! Ive learnt whati need too i think and the next tutorial sounds cool!

Happybracket
05-22-2010 07:17 PM
Find all posts by this user Quote this message in a reply
xLite Offline
Registered

Posts: 860
Joined: Apr 2008
Reputation: 13
Post: #5
RE: [AS3]Building an MMOCC - Part 2
Awesome! As usual please let me know if there is anything that should be included in this tutorial before I start the next. Happybracket

[Image: 0a232ed4862b3be39b47dd42f2fd57ba.gif]
The Ultimate Battle... who will win?
05-24-2010 06:18 AM
Visit this user's website Find all posts by this user Quote this message in a reply
lewisfroom Offline
Registered

Posts: 168
Joined: Nov 2008
Reputation: -2
Post: #6
RE: [AS3]Building an MMOCC - Part 2
Nope you have missed nothing.

Happybracket
06-18-2010 06:08 AM
Find all posts by this user Quote this message in a reply
fruits Offline
Registered

Posts: 1
Joined: Jun 2010
Reputation: 0
Post: #7
RE: [AS3]Building an MMOCC - Part 2
Waits impatiently for next tutorial. + Rep Happybracket
(This post was last modified: 06-20-2010 10:11 AM by fruits.)
06-20-2010 10:08 AM
Find all posts by this user Quote this message in a reply
Backthehelloff Offline
Registered

Posts: 27
Joined: Jul 2010
Reputation: 0
Post: #8
RE: [AS3]Building an MMOCC - Part 2
Come one next tutorial!!!! Or Im typing google ColonPP
07-11-2010 10:44 AM
Find all posts by this user Quote this message in a reply
Jacob Offline
Registered

Posts: 53
Joined: Jul 2010
Reputation: 1
Post: #9
RE: [AS3]Building an MMOCC - Part 2
Whens the next tut gonna be? (& +Rep)

[ERROR404;SIGNATURE NOT FOUND]
[Image: Jacob111.gif]
The image on my sig. wont work :l Help?
07-11-2010 10:51 PM
Find all posts by this user Quote this message in a reply
xLite Offline
Registered

Posts: 860
Joined: Apr 2008
Reputation: 13
Post: #10
RE: [AS3]Building an MMOCC - Part 2
The next tutorial is up! Check it out at http://mmoccforum.com/showthread.php?tid=17964.

[Image: 0a232ed4862b3be39b47dd42f2fd57ba.gif]
The Ultimate Battle... who will win?
07-31-2010 05:21 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump: