Sunday, June 27, 2010

AS3 Beginner Tutorial - part 1: Introduction

This tutorial is meant for people who are unfamiliar with Actionscript 3 and want to start learning it. In this tutorial we will see what's new in AS3, take a look a the variables, learn how to make simple buttons, preloaders and mouse followers.

This tutorial is not just meant for Adobe Flash users. If you're using another AS3 software, such as Flash Develop, you will be able to follow the logic and use the same code, however, you won't be able to draw and create movie clips (F8), you will need to write your code in classes, and more.

Actionscript 3 differs from AS 2 and 1 a lot. It even needs a new virtual machine to run - AS2 and AS1 ran on AVM1 (Actionscript 1 virtual machine), while AS3 uses AVM2 (sometimes called AVM+). But still, Actionscript remains Actionscript and you might find the new language not so new. Sometimes, AS3 might look similar to AS2. Sometimes.

However, there are changes. AS3 is more C++ like, it is more powerful than AS2 (note, I said powerful, not easier). Let's take a look at the changes:

- All scripting errors show up as they are played in the swf (helps fixing bugs!)
- All actionscript can be written only on frames. You can't do it on movie clips or buttons!
- Introducing event listeners (read on)
- New features in the flash itself - new method of displaying objects on the screen, as well as new tools - 3d rotation and bone kinematics.
- More and more features, which I will not state here right now.

Variables

In AS3, when defining a variable, you always have to include var in the beginning (which was optional in AS2).

var myAmazingVariable; // creates a variable, var required
var myGreatVariable = "greatValue"; // creates a variable with a value
myGreatVariable = "anotherValue"; // changes the value of an existing var
var myGreatVariable = "oneMoreValue"; // error: var already exists!

var is only used for creating variables.If you want to edit an existing one, simply write it without var.

Types of variables

Different variables might have different applications. AS3 has typed variables. That means you can create a Number variable that can only have a value of numbers, etc.

var anytype:*; // any type, default: undefined
var myboolean:Boolean; // true or false, default: false
var mynumber:Number; // sets numbers, default: NaN
var myinteger:int;
var unsignedinteger:uint;
var mystring:String; // text, default: null
var myobject:Object; // default: null

Full documentation on objects can be found here.

Integers and unsigned integers (int & uint) are new classes for AS3. They are basically numbers, but with minimum and maximum values (int - -2,147,483,648 to 2,147,483,647; uint - 0 to 4,294,967,295). Round numeric values only. Default value is 0.

Related:

AS3 Beginner Tutorial - part 2
AS3 Beginner Tutorial - part 3

9 comments:

Anonymous said...

How is this a beginners guide?. I want to understand and eventually learn AS, I am a photoshop artist that wants to understand game design, and after reading through countless Ebooks and so called "beginner" tutorials, ive learnt one thing, AS pros dont understand the meaning of the word "beginner".

Take this beginners tutorial for example, i read the title and i was like "awesome, if i stick with this and follow it word for word, ill know AS like the back of my hand", but then you start talking about swf, movieclips and defining variables, instead of saying "this is what an swf looks like, this is what it does, this is how you create it". Remember, beginner means beginner, i dont know anything about AS, all i know is i want to write game code. If you know of a string of tutorials that treats me like a dummy and walks me by the hand, please dont keep it a secret
mercy street guys, getting desperate lol

Kirill Poletaev said...

This is a beginners tutorial for the Actionscript 3 language, not the Adobe Flash software. This was aimed for people who already know the basics of the program, and know the meaning of the terms you've stated, aka for the people that are familiar with the interface and have drawn/animated in Flash before.

So, I suggest you read some tutorials about the basics of the Flash program (I assume its the one you are using?), and when you get a hand of it, move on to action script.

Good luck!

Anonymous said...

Thanks

Anonymous said...

I also would like to say, I know Flash and it's interface but.

I have no grasp on Scripting after reading this it just throws Var and blah blah blah at me it's only confusing.

He states at the top you are able to use this tutorial without Flash yet he goes off about things that would just confuse you if you don't use the program.

Kirill Poletaev said...

If you are completely new to programming, then you are probably right, this tutorial would leave the reader with some questions.

However, when I was writing this, I assumed that the reader is familiar with the very basics of scripting, for example, the meaning of variables in scripting.

Ideally, this tutorial would probably suit most the person that is trying to convert from AS2 to AS3, but someone with at least minimal knowledge in programming and very basic experience in other languages would find this tutorial just as helpful.

At this stage of the tutorial, Flash (or any other program actually) is not needed at all.

Please, if you have any specific questions, ask ahead and I will try to answer them.

Anonymous said...

Found your Blog a couple months ago and IT IS AWESOME. You've done such a great job at introducing, explaining, and elaborating on things for people like me (AS3 noob). Just want to say thanks!

nel said...

awww.. it seems to me that the photoshop artist is angry xD

Anonymous said...

Definitions of things would be nice to go along with the examples. This tutorial is a bit confusing

Vick Sa said...

HTML tutorial for beginners with examples

Free online HTML tutorial for beginners with examples - HTML tutorial will help you in creating website, after study the tutorial you will just one step ahead of creating your own website. HTML is easy to understand and you will enjoy it to learn. HTML tutorial contains hundreds of examples to better understand.

http://www.willvick.com/
http://www.willvick.com/HTML-tutorial-for-beginners-with-examples/HTML-tutorial-for-beginners-with-examples.aspx

Post a Comment