Be a Supporter!

AS:Beginning

  • 7,548 Views
  • 30 Replies
New Topic Respond to this Topic
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
AS:Beginning 2005-10-02 09:53:56 Reply

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

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS:Beginning 2005-10-02 10:18:38 Reply

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
Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:Beginning 2005-10-02 10:19:17 Reply

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
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS:Beginning 2005-10-02 10:20:43 Reply

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

Datalore
Datalore
  • Member since: Jul. 26, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS:Beginning 2005-10-02 10:21:57 Reply

yay! another addition to the AS topic :D

caseyo
caseyo
  • Member since: May. 14, 2005
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to AS:Beginning 2005-10-02 10:29:19 Reply

Nice, this could help cut down the crap threads.

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:Beginning 2005-10-02 10:31:20 Reply

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
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS:Beginning 2005-10-02 10:34:49 Reply

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

T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS:Beginning 2005-10-02 11:08:29 Reply

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.

Devenger
Devenger
  • Member since: Dec. 24, 2004
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:Beginning 2005-10-02 11:19:04 Reply

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.

piefi
piefi
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS:Beginning 2005-10-02 12:10:24 Reply

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

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:Beginning 2005-10-02 12:13:22 Reply

My first AS was a basic movement code.


BBS Signature
Foodenface275
Foodenface275
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to AS:Beginning 2005-10-03 09:07:49 Reply

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.

Musician
Musician
  • Member since: May. 19, 2005
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to AS:Beginning 2005-10-22 15:57:58 Reply

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.


I have no country to fight for; my country is the earth; I am a citizen of the world
-- Eugene Debs

BlackmarketKraig
BlackmarketKraig
  • Member since: Dec. 8, 2004
  • Offline.
Forum Stats
Member
Level 32
Artist
Response to AS:Beginning 2005-11-01 12:38:08 Reply

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
Mogly
Mogly
  • Member since: Sep. 5, 2004
  • Offline.
Forum Stats
Member
Level 25
Animator
Response to AS:Beginning 2005-11-01 12:46:48 Reply

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
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS:Beginning 2005-11-01 13:51:48 Reply

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

pesrow
pesrow
  • Member since: Oct. 13, 2004
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to AS:Beginning 2005-11-01 16:54:39 Reply

this was really usefull. thanks very much!

Murch
Murch
  • Member since: Feb. 26, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to AS:Beginning 2005-11-01 17:09:54 Reply

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.

IWantSomeCookies
IWantSomeCookies
  • Member since: Aug. 20, 2004
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS:Beginning 2005-11-01 17:10:14 Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS:Beginning 2005-11-02 12:24:56 Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS:Beginning 2005-11-17 12:37:32 Reply

AS: Beginning AS 2


- Matt, Rustyarcade.com

luigis-toilet
luigis-toilet
  • Member since: Jan. 3, 2006
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:Beginning 2006-04-17 07:41:10 Reply

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

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

Paranoia
Paranoia
  • Member since: Apr. 22, 2005
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Response to AS:Beginning 2006-04-17 09:25:36 Reply

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
Greensinge
Greensinge
  • Member since: Apr. 27, 2003
  • Offline.
Forum Stats
Member
Level 11
Gamer
Response to AS:Beginning 2008-05-07 19:45:54 Reply

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

Ramenberga
Ramenberga
  • Member since: Jan. 18, 2008
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS:Beginning 2008-05-20 12:39:53 Reply

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?

kylelyk
kylelyk
  • Member since: May. 15, 2008
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS:Beginning 2008-07-06 11:00:03 Reply

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
DontLikeYou
DontLikeYou
  • Member since: Jul. 2, 2008
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to AS:Beginning 2008-07-06 11:50:52 Reply

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


<a>

estftbl60
estftbl60
  • Member since: Jul. 4, 2008
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to AS:Beginning 2008-07-11 20:34:53 Reply

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

TheAlphaXany
TheAlphaXany
  • Member since: May. 1, 2007
  • Offline.
Forum Stats
Member
Level 07
Musician
Response to AS:Beginning 2008-08-23 11:09:29 Reply

how would i go about tracing a number variable?

(sorry for posting so late)


BBS Signature