Flash - First Program Ever

IAMGAMEDEVELOPER - Firstly, open Adobe Flash and FlashDevelop. You can find them in http://www.adobe.com/downloads/ and http://www.flashdevelop.org/. Also, it is recommended to install Adobe Flash Player http://get.adobe.com/flashplayer/.


Let's go into FlashDevelop. Create New Project ( Choose Project in Menu bar -> New Project ). Choose the first one, Flash IDE Project (Actionscript 3). Change the Name of your Project, in this case I change it into "Test". Configure the location if necessary. Let the package be blank, and click Ok.

Now on the Project Panel, you will see a directory of your project. Right click on it, and choose Explore. It will open the folder of your project. Next, go to Adobe Flash, and create New -> Flash File (ActionScript 3.0). Save it in the same folder with your project. You may name it your own, in this case, I name it "Test".


After that, go to FlashDevelop, and you will see the Project has a child now. Right click on your project, choose Add -> New Class. Change the name into Main, then click Ok. Your new class will be generated and placed in the same folder with your project.


Let's briefly read this simple structure of code. Basically, your class is located inside a package. As you can see, in the line 2 and 17, there is a pair of curly parentheses, it means that the code inside it is placed inside the package. Line 3 until Line 6 is a comment form, it won't be executed, but it is very useful in the development process as there will be so many lines of code, and you may forget what is the use of this code, this code, and that code. 

Next, in line 10, the class is declared. The name must be same with the name of the file. Inside the class you see similar declaration with the class, but without the word "class". It is called a constructor. Basically, constructor is called at the first time the code is executed.

Let's write something here. trace is basically a function for printing some value inside the output panel. Output is a field of  record of your program when it is executed. So, we try to print "Bang!". It uses " " sign because trace function read string data type to be printed in the log.


Now, go to Adobe Flash, Choose Window -> Properties -> Properties, or if you use Windows OS, you may press Ctrl+F3. Change the Document class into the name of your class, in this case, Main. Then, Choose Control in Menu bar -> Test Movie, or if you use Windows OS, you may press Ctrl+Enter.


Congratulations! You just got your first error. The class 'Main' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type. Let's simply solve it. Go to FlashDevelop, change your code a little bit, into something like the picture below. You may see the difference, there is a word 'extends' next to your class. The word extends means that the class adds properties of what it extends, in this case it extends MovieClip. What is Movieclip? you may read it here, it is officially made by Adobe. Last, import flash.display.MovieClip is a command to import MovieClip class.


Let's execute the program once again, and what is the result? Let me know, you may post it in the comment box of this post.

No comments:

Post a Comment