Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  Getting started with Actionscript 3.

Getting started with Actionscript 3.

By Milan Toth | Published 05/25/2007 | Beginner | Rating:
Milan Toth
Milan Toth is the Chief Flash Developer of Jasmin Media Group, he created one of the world's biggest flash media server system. He loves Eclipse and OS X, AS3 and JAVA, sci-fi and horror, metal and electronic.
 

View all articles by Milan Toth
Part One - Creating a simple program
Actionscript 3 is an ECMAScript-based programming language. I don't want to get into AS3 deeply, what we need to know it is object-oriented, and a virtual machine is needed to run AS3 programs, it is called AVM2 ( Actionscript Virtual Machine 2 ), and it is bulit in Flash Player 9. AS3 code can be edited with several programs, and can be compiled with the free Flex Development Kit provided by Adobe, but the fastest and easiest ( and most recommended ) development environment is Adobe Flex Builder, or Adobe Flex Builder plug-in for Eclipse. That's why we use Flex Builder in this tutorial.

Let's start with something easy, create a simple orange circle first. Open Flex Builder, File menuitem -> New -> Actionscript Project, type FirstCircle for name, and press Enter.

There should be a Navigator view on the left, showing our project files, and a big editor view on the right, showing FirstCircle.as, and a basic AS3 code :

package
{
    import flash.display.Sprite;
   
    public class FirstCircle extends Sprite
    {
        public function FirstCircle( )
        {
           
        }
    }
}


This is our main class, the "entering point" of our program. It is in the root package, and it is extended from the Sprite class, because AVM2 needs something visible for main class, we cannot create non-visible AS3 programs.

Let's compile and run this class. Run menuitem -> Run, and your default browser appears with a big blueish grey screen, and nothing happens. That is good, because we didn't write anything in the main class yet.

So, let's draw an orange circle. We need a displayobject with graphical abilities, there are three of this kind: the Shape, the Sprite and the MovieClip. Because we don't need a timeline and child display objects, we use the simplest class, the Shape.

package
{
   
    import flash.display.Sprite;
    import flash.display.Shape;
   
    public class FirstCircle extends Sprite
    {
       
        public function FirstCircle()
        {
           
            // creating a new shape instance
            var circle:Shape = new Shape( );
            // starting color filling
            circle.graphics.beginFill( 0xff9933 , 1 );
            // drawing circle
            circle.graphics.drawCircle( 0 , 0 , 40 );
            // repositioning shape
            circle.x = 40;                                 
            circle.y = 40;
           
            // adding displayobject to the display list
            addChild( circle );
       
        }
       
    }
   
}


For tips on how to use Shape or DisplayObject's graphics use Flex Builder's built-in language reference, or Adobe's LiveDocs. The other important thing is the last row "addChild". DisplayObjects are no longer depth-organized, as in previous versions of actionscript, we have to attach them to displayobject containers instead to make them visible. They still have a .visible property, but that is a little bit different.


Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Related Articles
Article Series
This article is part 1 of a 2 part series. Other articles in this series are shown below:
  1. Getting started with Actionscript 3.
  2. Camera-motion controlled ball
Comments
  • Comment #1 (Posted by frank - fmixson at ameritech.net)
    Rating
    I like the site, and the first 2 tutorials I looked where great. This however, says its for beginners, and thats me, for sure. But the first thing you say to do is open 'flex builder'. What is that? What does it have to do with A.S. 3.0? Better yet, what does it have to do with Flash? I stopped reading it after that.

    If this is not a beginner's tut, label as such, please. You seem be assuming a lot about us.

    The history was nice, but prerequisite knowledge should be listed. A quick goal could be stated.. a summary of whats going to be done in the tut to teach lesson.. (what the example will be about). Stuff like that.. so we're not wondering whats going on

    Thanks!
     
  • Comment #2 (Posted by rashmin - rayrash at rediffmail.com)
    Rating
    yes i believe frank is very much true since as i saw the heading 'begginer' i thought some basics must have been cleared..but to our amusement, i saw the word flex builder. hence forth pls clarify....such things .... think of us a dummies...
     
  • Comment #3 (Posted by Jon Perez - jbperez808 at yahoo.com)
    Rating
    This article is exactly what I was looking for. It seems that all the manuals and books out there fail to show a straightforward and simple way of compiling actionscript source code directly to SWF.
     
  • Comment #4 (Posted by Karl - defcom2 at gmail.com)
    Rating
    Thank you very much for your tutorial!! I am a begginer and found it very informative. The stuff I didn't know about I used my commonsense and googled it. Thanks for spending some of your time to educate others! Appreciated!
     
  • Comment #5 (Posted by Jon Perez - jbperez808 at yahoo.com)
    Rating
    This tutorial was exactly what I was looking for. I do agree with the author that it is a beginner level tutorial, but mainly for those who already know how to code.
     
  • Comment #6 (Posted by zalah)
    Rating
    First Run, test movie and I've gotten two errors from the start.
    1046: type was not found or was not a compile-time constant: Shape
    1180: Call to a possibly undefined method shape.

    What a waste of time and effort.

     
  • Comment #7 (Posted by Kristall - sternlganz at gmx.de)
    Rating
    -----------------
    @zalah
    You must import
    flash.display.Shape;
    Then you didn't get this error.
    -----------------

    It is a very good Tutorial for Beginners, who know other programming languages.

    Greetings
     
  • Comment #8 (Posted by Mohamed - khalifmk at samref.com.sas)
    Rating
    When I first read the very first few lines of the article, I thought I was so stupid since it is supposed to be a beginner's and I have been developing materials using flash for quite some time now. However, after reading some of the comments I feel I am not the only one in the dark.

    Thanks
     
  • Comment #9 (Posted by umit - omurgasiz at gmail.com)
    Rating
    thank you very much. this and the second part of this tutorial very cleared my mind about creating class methods.

    appreciated !:)
     
  • Comment #10 (Posted by Dasn - info at danieldewald.com)
    Rating
    All works fine but
    After changing the MovingCircle.as at the last step I get this error:

    TypeError: Error #1007: Instantiation attempted on a non-constructor.
    at MovingCircle()
    at FirstCircle/init()
     
Submit Comment



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.