Forum Topic: AS:Beginning

(5,727 views • 30 replies)

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/2/05 09:53 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

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


None

Rantzien

Reply To Post Reply & Quote

Posted at: 10/2/05 10:18 AM

Rantzien FAB LEVEL 15

Sign-Up: 01/27/05

Posts: 3,426

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

None

Toast

Reply To Post Reply & Quote

Posted at: 10/2/05 10:19 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,921

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

Good work :D


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/2/05 10:20 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

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


None

Datalore

Reply To Post Reply & Quote

Posted at: 10/2/05 10:21 AM

Datalore FAB LEVEL 10

Sign-Up: 07/26/05

Posts: 18

yay! another addition to the AS topic :D


None

caseyo

Reply To Post Reply & Quote

Posted at: 10/2/05 10:29 AM

caseyo DARK LEVEL 23

Sign-Up: 05/14/05

Posts: 4,924

Nice, this could help cut down the crap threads.


None

Toast

Reply To Post Reply & Quote

Posted at: 10/2/05 10:31 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,921

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...


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/2/05 10:34 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

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


None

T-H

Reply To Post Reply & Quote

Posted at: 10/2/05 11:08 AM

T-H LIGHT LEVEL 39

Sign-Up: 01/07/04

Posts: 4,893

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.


None

Devenger

Reply To Post Reply & Quote

Posted at: 10/2/05 11:19 AM

Devenger NEUTRAL LEVEL 09

Sign-Up: 12/24/04

Posts: 1,103

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.


None

piefi

Reply To Post Reply & Quote

Posted at: 10/2/05 12:10 PM

piefi EVIL LEVEL 07

Sign-Up: 05/07/05

Posts: 371

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


None

Toast

Reply To Post Reply & Quote

Posted at: 10/2/05 12:13 PM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,921

My first AS was a basic movement code.


Happy

Foodenface275

Reply To Post Reply & Quote

Posted at: 10/3/05 09:07 AM

Foodenface275 NEUTRAL LEVEL 04

Sign-Up: 10/01/05

Posts: 2

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.


None

Musician

Reply To Post Reply & Quote

Posted at: 10/22/05 03:57 PM

Musician EVIL LEVEL 04

Sign-Up: 05/19/05

Posts: 2,199

At 10/2/05 10:20 AM, Ninja-Chicken wrote: these threads are going to be assuming that you know NOTHING

I believe there is a tutorial like that that was made before this one.


None

BlackmarketKraig

Reply To Post Reply & Quote

Posted at: 11/1/05 12:38 PM

BlackmarketKraig NEUTRAL LEVEL 32

Sign-Up: 12/08/04

Posts: 7,514

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.

: [ fl ] : + : [ art ] : + : [ dA ] : + : [ ms ] : + : [ <3 ] :
. l . o . v . e .

BBS Signature

None

Mogly

Reply To Post Reply & Quote

Posted at: 11/1/05 12:46 PM

Mogly LIGHT LEVEL 25

Sign-Up: 09/05/04

Posts: 10,336

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

~ MogTom ~ Dont fuck around with my dog. All that I can see I steal. ~
NG FFR ~ Automatic for the people.

BBS Signature

None

Rustygames

Reply To Post Reply & Quote

Posted at: 11/1/05 01:51 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

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


None

pesrow

Reply To Post Reply & Quote

Posted at: 11/1/05 04:54 PM

pesrow EVIL LEVEL 06

Sign-Up: 10/13/04

Posts: 22

this was really usefull. thanks very much!


None

Murch

Reply To Post Reply & Quote

Posted at: 11/1/05 05:09 PM

Murch NEUTRAL LEVEL 24

Sign-Up: 02/26/05

Posts: 951

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.


None

IWantSomeCookies

Reply To Post Reply & Quote

Posted at: 11/1/05 05:10 PM

IWantSomeCookies LIGHT LEVEL 13

Sign-Up: 08/20/04

Posts: 3,295

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


None

Rustygames

Reply To Post Reply & Quote

Posted at: 11/2/05 12:24 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

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


None

Rustygames

Reply To Post Reply & Quote

Posted at: 11/17/05 12:37 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662


Thinking

luigis-toilet

Reply To Post Reply & Quote

Posted at: 4/17/06 07:41 AM

luigis-toilet LIGHT LEVEL 08

Sign-Up: 01/03/06

Posts: 104

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

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


None

Paranoia

Reply To Post Reply & Quote

Posted at: 4/17/06 09:25 AM

Paranoia DARK LEVEL 34

Sign-Up: 04/22/05

Posts: 9,699

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

Elated

Greensinge

Reply To Post Reply & Quote

Posted at: 5/7/08 07:45 PM

Greensinge LIGHT LEVEL 11

Sign-Up: 04/27/03

Posts: 483

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 :)


Questioning

Ramenberga

Reply To Post Reply & Quote

Posted at: 5/20/08 12:39 PM

Ramenberga LIGHT LEVEL 02

Sign-Up: 01/18/08

Posts: 5

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?


None

kylelyk

Reply To Post Reply & Quote

Posted at: 7/6/08 11:00 AM

kylelyk LIGHT LEVEL 10

Sign-Up: 05/15/08

Posts: 490

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

None

DontLikeYou

Reply To Post Reply & Quote

Posted at: 7/6/08 11:50 AM

DontLikeYou DARK LEVEL 05

Sign-Up: 07/02/08

Posts: 196

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

<a>


Elated

estftbl60

Reply To Post Reply & Quote

Posted at: 7/11/08 08:34 PM

estftbl60 NEUTRAL LEVEL 04

Sign-Up: 07/04/08

Posts: 4

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


Questioning

TheAlphaXany

Reply To Post Reply & Quote

Posted at: 8/23/08 11:09 AM

TheAlphaXany DARK LEVEL 07

Sign-Up: 05/01/07

Posts: 25

how would i go about tracing a number variable?

(sorry for posting so late)

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 03:29 AM

<< Back

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!