First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing! | Flash Jobs
Search tutorials
Author: Aditya Sharma aka adit_ya_sharma | Website: http://www.ctoffakes.tk
Steps for .as file and class creation:- 1)Create a new actionscript document (.as) by clicking on 'New' on the menu bar and then selecting Actionscript file and pressing 'ok'. The .as file should be in the same folder as the .fla file. 2)In the acionscript file, we are going to create a class for the functioning of the MovieClip 'Circle'. 3)Since the class name and the .as file name should be the same, save the .as file with the name 'Circle'. 4)Now we create the class like this:-
class Circle
{
}
Note: In AS 2.0, in this example, since I want to move the movieclip to the right, my 'Circle' class should include all the predefined methods of a 'MovieClip' and should be able to use different properties like _x and _y, which are the members of the 'MovieClip' class. Hence for using them, we would use the 'extends' keyword, to include all methods and properties of the 'MovieClip' class into our 'Circle' class. This might remind you of the similar syntax used in java for inheritance.
5)So the class now looks like this:-
class Circle extends MovieClip
{
}
6)As I had mentioned before, a constructor should always be written inside it. The constructor is a function with the same name as the class which is defined inside it. Simply remember, a constructor function is called whenever an object of the class is created. Currently, I'll make a new MovieClip type variable in the class, and when the instance of the MovieClip in .fla file will be passed, MovieClip type variable will be equaled to that instance name for the reference to the 'circle_mc' MovieClip. So now the class looks like:-
class Circle extends MovieClip
{
   var circle_mc:MovieClip;
   
   function Circle(passed_mc:MovieClip)
   {
	circle_mc = passed_mc;
   }
}
7)Our basic aim is to move the circle right when we press the Right Arrow Key, so the class should have a function to handle this action. This will be done by making a method (or function) for executing the code for moving the MovieClip, which is specified as Public for access from anywhere in the class. The class looks like this:-
class Circle extends MovieClip
{
   var circle_mc:MovieClip;
   
   function Circle(passed_mc:MovieClip)
   {
	circle_mc = passed_mc;
   }
   public function moveRight():Void
   {
	circle_mc._x += 1;
   }   	
}
Note: Look at the keyword "Void". This the return type specified, because the method is not returning any value, it is simply executing a statement.
8)Save your .as document. Now we will create an object of the class and move the MovieClip...
» Level Intermediate

Added: 2005-10-12
Rating: 7 Votes: 9
(10 being the highest)
» Author
Iam a flash actionscript programmer.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.