flash animation video tutorials

 

 

 

 

 

START LEARNING
FLASH NOW

Get instant access to over
45 minutes of FREE Flash tutorials on video
 and our newsletter.

Name:
E-Mail:

.

.

.

 
Web video-animation.com

.

.

flash tutorials flash tutorials flash tutorials flash tutorials

Interfaces in Actionscript 2.0

The Flash MX2004 AS 2.0 reference Docs state this for interfaces:

  • Interfaces contain only declarations of methods, not their implementation. That is, every class that implements an interface must provide an implementation for each method declared in the interface.
  • Only public members are allowed in an interface definition. In addition, instance and class members are not permitted.
  • The get and set statements are not allowed in interface definitions.

What does it all mean ? Well bear with me and I will try and make it understandable. Interfaces look like classes except for the keyword "interface" instead of class in it declaration. All of the methods will contain no code, just declarations. When you create a class that uses the interface , you include the keyword "implements" then the interface name. Lets show you an example. First we will create a Moving class:

interface Moving{
	public function move();
} 

Now we want to create a class that will use our interface:

class Spaceship extends MovieClip implements Moving{
	
	// this class must at least declare all the 
	// methods of Moving
	public function move(){
		ship_mc._x += 10;
	}
}

Go to Flash and create a movieClip of your spaceship and in the linkage panel, type "Spaceship" in the identifier textfield. Type Spaceship in the AS 2 class field. And to call it, in our Flash Actions Panel type something like:

attachMovie("Spaceship", "myship",1);
_root.onEnterFrame = function(){
	myship.move();
}
flash 8
.