Categories
AS3 Flash

AS3 – take one step at a time: step 1

I finally started programming with ActionScript 3 (AS3); I know, I not a early adopter… 😉

And the first steps in AS3 are as uncomfortable as the first time I started OOP programming … or when I started moved from AS1 to AS2…

Since I started working for NOISE 5 months ago and moved to Amsterdam, I haven’t had time to do learn AS3.
That luckily has changed 🙂 and I started learning the basics.

And the first obstacle I ran into was something very simple: I always use a basic document (FLA) with default library items, some layers I always use and some ActionScript code to align the stage:

_root._quality = "BEST";
Stage.scaleMode = "noScale";
Stage.showMenu = false;
Stage.align = "TL";
stop ();

I have this also in a class (AS2), so I thought it would be useful to rewrite this class in AS3.
and I wanted to use this in my new as3 files too… (remember that this is the first thing a tried)

First you need to create a document class:

Document Class
And in my case my document class was: ‘Main’


package  {

	public class Main {
		
		public function Main() {
			trace ('Main')			
		}
		
	}
	
}

(package generated by FlashDevelop)

Code didn’t pass; I got a Compiler Error:
5000: The class 'Main' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.


package  {

	public class Main extends MovieClip {
		
		public function Main() {
			trace ('Main')			
		}
		
	}
	
}

I got some new errors:

  1. 1017: The definition of base class MovieClip was not found.
  2. 5000: The class ‘Main’ must subclass ‘flash.display.MovieClip’ since it is linked to a library symbol of that type.

So I added import flash.display.MovieClip;


package  {

	import flash.display.MovieClip;
	
	public class Main extends MovieClip {
		
		public function Main() {
			trace ('Main')
		}
		
	}
	
}

Ahhh and now we can get the stage to work with my ‘old code’, let’s paste it into the new document:


package  {

	import flash.display.MovieClip;
	
	public class Main extends MovieClip {
		
		public function Main() {
			trace ('Main')
			_root._quality = "BEST";
			Stage.scaleMode = "noScale";
			Stage.showMenu = false;
			Stage.align = "TL";
			
		}
		
	}
	
}

Auw: both _root and Stage doesn’t excited no more: I got an migration error


package  {

	import flash.display.MovieClip;	
	import flash.display.Stage;
	import flash.display.StageQuality;
	
	public class Main extends MovieClip {
		
		public function Main() {
			trace ('Main')
			stage.quality = StageQuality.BEST;
			stage.scaleMode = "noScale";
			stage.showDefaultContextMenu = false;
			stage.align = "TL";
		}
		
	}
	
}

And at last it works…
The only thing now to do, is to put it in the correct package.