00:00
00:00
Newgrounds Background Image Theme

Arnahan just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS:Beginning 2005-10-02 09:53:56


AS:Main

AS: Beginning

Though AS:Main has become an invaluable asset to actionscripters I think the hardest thing to do is actualy begin programing.

How do you know where to start? Well this AS:Thread (or probally series of threads) is for those of you whom are confused by

the hundreds of topics explaining every little thing in detail. This thread will give you a basic understanding of

actionscript and point you in the right direction for expanding your skills.

Your first step

Okay first thing is first open flash. I am using Flash 8 for this but Flash MX 2004 should be fine as well as Flash MX. I do

suggest you upgrade to Flash 8 though.
Okay once youve opened flash create a new document and saved it; call it "my_flash" for now). Next open the actions panel by

pressing F9. Okay here you will see 4 boxes above a window where you can input your code. From left to right they are:
1) Add new Item to script - we will not be using this because all it does is types the command for you
2) Find/Replace - This can be used to quickly find and/or replace keywords within your code
3) Target path - This is very useful as it allows us to find the target path between 2 movieClips relativly or absolutely
4) Check syntax - This is the most useful thing up there because it tells you if your code is wrong and whats wrong with it
5) Auto format - Very useful it neatens up the code
6) Show code hint - Very useful when you forget the input parameters for functions
7) Debug options - This is just for editing breakpoints etc and we wont be using it in this tutorial

Okay so now we are familiar with the actions panel (Fig 1) we can begin with some AS

Your first lines of code

Okay now click on the first frame and go onto the actions panel. Type in:
trace ("hello world")
Press Ctrl+Enter to test your movie and how exciting you should get a window saying "hello world"
Excited? Lets go through the code

the trace function
Trace is a function used only when debugging your flash document and wont show up in the final .swf file. Trace basically

displays whatever you tell it to in the output panel. In this case we put in "hello_world" which is enclosed by "" meaning it

is a string.

Difference between strings and variables in the tracefunction

You can trace strings which are always constant ie "hello_world" would output hello_world or varables by not using "". Lets

take a look at variables

Variables

When declaring a variables you must give it 3 things.
- A name
- A type
- A value

and we use the keyword Var to declare a variable

So in frame 1 put

var message:String = "hello_world"

See what we did there

we gave it the name message the type String (you have to put a : after the name) and gave it the value of "hello_world". So...

var message:String = "hello_world"
trace (message)

When we tested it it would output

hello_world

Are you amazed?

+-/*=

We can also use +, -, / and * to manipulate variables. + is the most important one for Strings because you could do

var message:String = "hello_world"
trace (message + " this is my first bit of AS)

And that would output

"Hello_world this is my first peice of AS"

Numbers

Now lets say we had
var num1:Number = 3
var num2:Number = 5
We can use the +, -, / and * to make it do different things

for example

num1 + num2 = 8
num1 - num2 = -2
num1 / num2 = 0.6
num1 * num2 = 15

And we could even trace them or better still put them into another variable by doing something like the following

var num1:Number = 3
var num2:Number = 5
var num3:Number = num1 + num2

Quick note: Remember that you dont have to assign a value to a variable when it is declared you can always just put
var goatse:String

Okay so now we know alot about variables and strings and how to use trace to debug your code I'll let you have a play with

those until next time

To expand on your knowlage of these things here are some links you should study before going on to part 2 of this tutorial

Debugging syntax
Maths basic
Variables

Fig 1 below

AS:Beginning


- Matt, Rustyarcade.com

Response to AS:Beginning 2005-10-02 10:18:38


Much of it is gone through in other threads, but it's still a very good idea to gather some basic things in one thread. I specifically liked the Actionscript panel part, that should be really helpful for some.
<3


BBS Signature

Response to AS:Beginning 2005-10-02 10:19:17


It was good :)
Keep up the good work :)
What an excelent idea :)
Not bad at al :)
I liked it very much :)

Good work :D


BBS Signature

Response to AS:Beginning 2005-10-02 10:20:43


At 10/2/05 10:18 AM, Rantzien wrote: Much of it is gone through in other threads, but it's still a very good idea to gather some basic things in one thread.

Yeah because I was talking to BeRuild about making a thread and he asked me what AS:Thread he should be looking at to begin learning and I realised that no thread doesnt ask that you know another peice of AS to read that one (if you know what I mean) so these threads are going to be assuming that you know NOTHING

I specifically liked the Actionscript panel part, that should be really helpful for some.

Yeah I hope so

<3

<3


- Matt, Rustyarcade.com

Response to AS:Beginning 2005-10-02 10:21:57


yay! another addition to the AS topic :D

Response to AS:Beginning 2005-10-02 10:31:20


At 10/2/05 10:29 AM, ElectricFreak wrote: Nice, this could help cut down the crap threads.

No it won't :)

N00bs won't bother to use the searchbar before making a new topic...


BBS Signature

Response to AS:Beginning 2005-10-02 10:34:49


At 10/2/05 10:31 AM, -Toast- wrote:
At 10/2/05 10:29 AM, ElectricFreak wrote: Nice, this could help cut down the crap threads.
No it won't :)

N00bs won't bother to use the searchbar before making a new topic...

Yeah but at least people can link them to somehting which will shut them up for a while rather then linking them to a very confusing (to the average n00b) AS:Main


- Matt, Rustyarcade.com

Response to AS:Beginning 2005-10-02 11:08:29


Yeah its all about flash build in help docs when you start. Gotta love em.

I think gotoAndPlay() was the first bit of AS i learnt.

Response to AS:Beginning 2005-10-02 11:19:04


First bit of AS I learnt was stop(); and it took a damn well long time to find it. :D

Errr, yeah, quite nice. Half of this post is just a bump. :D But seriosuly, this should help, if we can only get more people to read this...


I'm back! on a temporary basis. No-one can remember who I am! but I don't really mind.

Response to AS:Beginning 2005-10-02 12:10:24


i did wonder why this hadn't been made before.
stop() was also my first AS.

Response to AS:Beginning 2005-10-02 12:13:22


My first AS was a basic movement code.


BBS Signature

Response to AS:Beginning 2005-10-03 09:07:49


wow this was really nice of you, because i don't know anything! about creating flash but this attuacly taught me the basics maybe ill check out ure flash sometime.

Response to AS:Beginning 2005-11-01 12:38:08


I thought I'd make a quick note on this, in case there are other actionscript n00bs like me who want to learn but are working with Flash MX (or possibly even Flash 5?).

For Flash MX people

Strict Data Typing wasn't introduced until Flash MX 2004 and therefore a few snippets of code from this tutorial won't work properly with older versions like MX.

var message:String = "hello_world"
trace (message)

will come up with a trace of: "undefined" in MX, so the :String part needs to be dumped.

MX version:
var message = "hello_world";
trace(message);

The same will be true of the :Number part in the later code.

I just wanted to get that out there, because often the early stages of learning something new are the most confusing and frustrating, and if something doesn't work right you haven't really developed the tools to fix it.


This sig is 100% effective protection from all hexes, curses, evil spirits and bad karma. Guaranteed.

BBS Signature

Response to AS:Beginning 2005-11-01 12:46:48


nice one NC, i also asked for something like this in AS:Main the other day :D


WEBSITE

BLOG ~ Dont fuck around with my dog. All that I can see I steal. ~

NG FFR ~ Automatic for the people.

BBS Signature

Response to AS:Beginning 2005-11-01 13:51:48


Thanks mr MX user : )
Mogly yeah I thought alot of people were asking "But where do I begin" so I made these


- Matt, Rustyarcade.com

Response to AS:Beginning 2005-11-01 16:54:39


this was really usefull. thanks very much!

Response to AS:Beginning 2005-11-01 17:09:54


At 10/2/05 09:53 AM, Ninja-Chicken wrote:
var message:String = "hello_world"
trace (message + " this is my first bit of AS)

Doesn't this code need a quote after "AS"?? I was just wondering.

Response to AS:Beginning 2005-11-01 17:10:14


Yeah, this is a nice tutorial.

Why are there loads of random new lines and spaces everywhere though?


"Actually, the server timed out trying to remove all your posts..."

-TomFulp

Response to AS:Beginning 2005-11-02 12:24:56


At 11/1/05 05:10 PM, IWantSomeCookies wrote: Yeah, this is a nice tutorial.

Why are there loads of random new lines and spaces everywhere though?

Dunno I wrote it in notepad and the BBS ate it : )

At 11/1/05 05:09 PM, Murch wrote:
At 10/2/05 09:53 AM, Ninja-Chicken wrote:
var message:String = "hello_world"
trace (message + " this is my first bit of AS)
Doesn't this code need a quote after "AS"?? I was just wondering.

yes its a misprint


- Matt, Rustyarcade.com

Response to AS:Beginning 2005-11-17 12:37:32



- Matt, Rustyarcade.com

Response to AS:Beginning 2006-04-17 07:41:10


Nice tutorial! Helped me a lot! just some tutorials more and i can start making my first game!

:D
:P
:)
;)
;P
;D

Response to AS:Beginning 2006-04-17 09:25:36


Wow, this came back up again. Still pretty useful, and I hope it catches the eyes of some people while it's up.

:)
:(
:O
:D
:P
;)

>:|
¦-|
):[


BBS Signature

Response to AS:Beginning 2008-05-07 19:45:54


Really helpful, I'm just getting into AS and this was a perfect start for me. I now understand variables etc. a lot more!

Thanks :)

Response to AS:Beginning 2008-05-20 12:39:53


Please don´t be mad with me just because im a noob, i mean this thread is meant for noobs.
The quetion:
What can i use variables for, except for showing what your score is in a game and stuff?

Response to AS:Beginning 2008-07-06 11:00:03


At 5/20/08 12:39 PM, Ramenberga wrote: Please don´t be mad with me just because im a noob, i mean this thread is meant for noobs.
The quetion:
What can i use variables for, except for showing what your score is in a game and stuff?

Hey I am kind of a noob too. Variables basically hold a value, whether it is a number, word, or relationship between 2 or more other values/objects. Yes it can be used for a score in a game, but it can limit clutter in a game. Say if you needed the value gravity(g) in your game/ physics program. If you needed g=.65 then you could do that. You might have to use that for alot of calcutations, but because you created that variable you don't have to typ in .65 in every time you need it. Instead you can type in g.
ex:
.65*h=j
.65*j*.65=o

gh=j
gjg=o


Kylelyk: Forwards and Backwards, Over and Out.

BBS Signature

Response to AS:Beginning 2008-07-06 11:50:52


Thanks man I dont know when/how to begin learnng this kind of stuff now I have a better Idea


<a>

Response to AS:Beginning 2008-07-11 20:34:53


This is really great man because i could never find any good beginning AS tut. This really helped me thanks! =)

Response to AS:Beginning 2008-08-23 11:09:29


how would i go about tracing a number variable?

(sorry for posting so late)


BBS Signature

Response to AS:Beginning 2008-08-23 11:21:24


At 8/23/08 11:09 AM, TheAlphaXany wrote: how would i go about tracing a number variable?
trace (2+2);

You really don't have to ask, you have a hundred places to find out. There's documentation for every function in Flash, press f1.


BBS Signature