ActionScript 3 101: Your First Script (Part 4)

Follow @tristarweb

In the last post we looked at setting up your own flash project, ready to start writing your first ActionScript 3 program.

We will be introducing you to a huge amount of scripting concept in the next couple of weeks and if you stay with us and practice each tutorial you could quite easily be coding up your own AS 3 projects within a few days. With ActionScript 3 now being a fully developed, object-orientated, language you will see similarities between other languages, such as PHP, JavaScript, JQuery, C, C#, Python, Pearl and many more. It should be easy to migrate from one to another once basic principles have been grasped.

We will start with the basics, however, and introduce you to the trace function first. Yes, this seems very boring and the trace function will hold no value in an end program, but it is invaluable when building more complex scripts and debugging in the future.

So let’s get started. On your main timeline, create a new layer and call it actions. Right Click on the first frame of this layer and select actions. This will open the actions panel.

Open ActionScript 3 Action Panel

Within this Action Panel is where you will write your script. Write the following:


var my1stNumber:Number = 0;

var my2ndNumber:Number =1;

trace(my1stNumber+my2ndNumber);

This is a simple script, and will output the sum of 0+1 in the output pane. This is useful when testing outputs, or checking if events have triggered in much more complex scripts.

In the next tutorial we will look at event listeners and basic functions.

About russell

Web Developer I’m a web developer with 3 years’ experience in the media industry.My Development skills includes flash, AS3, AS2, HTML, CSS, JavaScript, Jquery, XML, PHP, and MySQL. I have a great deal of experience developing interactive user interfaces in PHP Javascript AS3 AS2I have two masters degrees in Computer Science and Multi Media and before my current role I completed a year of research at De Montfort University researching multi touch technology. during this time I developed several multi touch applications for entertainment spaces.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please wrap all source code with [code][/code] tags.

Follow Tristar on Twitter