Page 1 of 1

Flash AS 3.0 Basics 1 - An Upgrade? [Flash CS4] Rate Topic: -----

#1 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1666
  • View blog
  • Posts: 8,547
  • Joined: 07-September 06

Posted 29 December 2008 - 11:05 AM

In this tutorial we will be going over some of the more major changes that Actionscript has gone through between AS 2.0 and AS 3.0 and talk about some of the confusion that you may be encountering with the new "improved" language.

Starting Out
For reasons of this tutorial I will ask that you start off a new Flash AS 3.0 Document and create a movieclip that you can easily recognize in comparison with the rest of the document. (You can easily create new symbols by hitting the F8 key, then set the symbol name (I left mine as Symbol 1, it isn't all that important), and the Type of Movie Clip).

I then gave my shape the instance nameof t, just because it is short and simple.

Looking at some major differences
If you have tried to program anything with AS 3.0 after being an AS 2.0 type of person you will see that most of your stuff doesn't work. There is a reason for this - the language has fundamentally changed. While it keeps much of the same syntax and attributes many of the functions, and attributes have been renamed or made more complex.

Here is an example of AS 2.0 in comparison with AS 3.0 for moving our nice movieclip across the stage (no stopping or turning around, just moving):

t.onEnterFrame = function(){
	this._x += 5;

In AS 3.0, that can no longer be changed (not only because onEnterFrame is no longer a standard called function for every MC, but because of how the language has progressed).

For AS 3.0 you have to add an Event Listener for every event (and I do mean every), as such the same code as above pans out to be:
t.onEnterFrame = function(evt:Event):void{
	t.x += 5;
addEventListener(Event.ENTER_FRAME, t.onEnterFrame);

NOTICE - t.x += 5;, AS 3.0 no longer recognizes that a function declared outside of an object is still pertaining to the object (If that makes any sense).

NOTE - I have added a :void after the declaration of my function, but before the curly brace. This is used as the function's return type, and while it is not required as of yet I can see it being required in AS 4.0 easily enough.

AS 3.0 does cut down on some of the code required if you are going about writing out everything in code though. For instance, if you wanted to create a rectangle that was 200 by 200 at leastion 10, 10 in AS 2.0 you could have to do this:
var mc:MovieClip = _root.createEmptyMovieClip("movieClip", 0);
	mc.moveTo(10, 10);
	mc.lineTo(200, 10);
	mc.lineTo(200, 200);
	mc.lineTo(10, 200);
	mc.lineTo(10, 10);

AS 3.0 has taken the time to get rid of the MovieClip.lineTo method (sadly enough, though you can get to it is you want to import the Graphics class), but it has also added a few functions to make creating things like squares easier:

var mc:MovieClip = new MovieClip();;, 10, 200, 200);;

NOTE - You have to tell the stage to add the new movieclip, you can't tell _root to do it anymore.

AS 3.0 has also added in a z-axis so you don't have to worry about finding a 3rd-party library to use it anymore.

The verdict
Well, the language sure has gone under some huge changes since the last round, but it is starting to look more like a programming language instead of a designer's tool. Whether this is a good or bad thing is totally up to you and your prefference on how things work.

There is definately a learning curve to AS 3.0 that may take people a while to catch up with, so hopefully Adobe doesn't have any huge changes coming to it for quite a while.

The End
I hope this helped you learn about a few of the changes made to AS and see the it is not totally different... just enough to make it annoying :)

Is This A Good Question/Topic? 1
  • +

Page 1 of 1