02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Setting Up Our Main Class

Get into a rhythm of efficiently setting up your files so you can smoothly transition into writing code. This video shows you how to set up your script for all the code you'll write from here on out.

After creating an ActionScript file, our next goal is to write the code. So, once all file tasks are done, we can start using that file. Before actually beginning to write code, there are a few basic things one must remember while dealing with programming:

  1. The number of braces that open must be equal to the number of braces that close. Hence, to maintain the balance between these braces, we must close every brace as soon as we open it. Thereafter, the code will go within these braces – this helps avoid any errors that might occur when there's a brace imbalance in a program. (02 Tip: In AS3, you can press Alt-quote and Flash will highlight all the code within the closest brackets: this can be a life-saver!)
  2. We must import all the required library files inside the section of the package. We must also include the parent class, which can be directly used in the program without rewriting it because of the overriding and overloading concepts.
  3. The main code is written in the Main() constructor function. Also remember that a function name is always followed by open brace '(' and a closed brace ')'. These parenthesis can either be empty or we can pass arguments through them. However, the concept of passing arguments into functions is a topic to which we'll dedicate an entire title, in later chapters of this series that cover working with functions.

Now, once you complete the code inside the main function, you must save the file in the source folder. The process of saving files in source and deploy folders has already been discussed in previous videos. You can take a quick peek at the previous videos to refresh your memory. One new thing here is that you must save your file with the same name of your main class. Moreover, the first letter of the class name must be in uppercase.

Now, we have two saved files: main.fla and Main.as. Hence, we must create a link between these two files:

Be sure you're in your main.fla file, then (if the properties panel isn't open,) select the window menu and click on the properties option.

When the properties panel is open, you can find the “Class” box. Type in the class name you just created without any extension (aka 'Main').

Finally, click on the small pencil next to the box: if your class editor opens, that means you did everything right. Way to go!

Video Transcript

00:00Well, we want to create a new file and to do that we're going to click on the file again and choose new
00:07After we've got our new file menu open. We're going to select an action script file and
00:13Click OK and a new action script file has been created
00:21I'm going to type now f4 which is going to make me go full screen so we could start typing code inside in full view
00:29So
00:30Now you don't really have to do that
00:32It's just to make things a bit more convenient and now I'm going to start typing a few things that are going to be a little
00:37Bit enigmatic and just get used to typing them right now
00:42And we're going to delve deeper into why in future videos
00:45And so I'm typing package, and I'm opening a curly bracket and closing a curly bracket
00:53I'm going to go back up and now I'm going to import
01:00flash
01:02display
01:03dot movie clip
01:05Make sure the everything turns green and make sure that you make sure that you import it
01:14you import space flash dot display dot all in lowercase and
01:20Then movie clip when the M and the C are in uppercase, and you're going to end it with a semicolon
01:28So now that we have our import flash display that will be given
01:31Don't worry about what we're actually doing right now. These are just our preps so we could start
01:37practicing flash and understanding things
01:40As we're introduced the things we're going to revisit this and see what what it actually is
01:45The next thing we want to type is public
01:49Class all in lowercase we're going to give a name to our class. We're going to call it main
01:55uppercase M
01:57We're going to open up a bracket a curly bracket and close a curly bracket bracket again
02:04And the last step that we want to do or we're going to re-go back up here
02:08And after we click after we type public main class main we're going to type space
02:15extends space
02:18Movie clip same way that you've done it in the import line
02:23Okay, now the last item that we want to add here last anemic item. We're going to add here is
02:30public
02:32function and a group we're going we're going to repeat the name of the class which is main when uppercase and
02:39this time around we're going to open
02:43Open and close a bracket a round bracket and then we're going to open a curly bracket
02:50Enter enter and we're going to close a curly bracket
02:53And this is all the preparations that we're going to do and right here. We're going to place our code
02:59so our code is going to come where I just highlighted and
03:04All our lessons are going to start from here so the next video. We're assuming that the structure is ready
03:09And we're going to start coding in this area now that we have our file all created
03:14We're going to want to save it
03:15So I'm going to click on my command s or you could go through your menu and select to save as
03:21Or whatever shortcut is on your operating system, so I'm going to click on save as and
03:27we're in our source folder and
03:29We're going to call our file the exact same name as we're calling our class itself, which is main actually
03:35We're going to call it uppercase M a n and
03:39I'm going to click on save and
03:41I have my main safe the last item that we want to do is link between our main and our FLA and
03:49As enigmatic as old these words are just follow step by step, and we're going to repeat this a few times and
03:56With practice we're going to understand why we're doing this
04:00Okay, so if I'm going I'm going to go back into my FLA by tapping into my FLA and in my main FLA
04:06Now that I'm going to still in full screens. I'm going to click on f4 to go back to a regular mode and
04:13I'm going to go to my menu and search for the properties panel
04:17And I found my properties panel
04:19I'm going to click on it and my properties panel is going to open up it might open up in different shapes
04:24But in that you will find in your publish settings a class path and
04:28In the class path we want to type
04:32main
04:34Uppercase M and that's it now to make sure that everything works if everything is working
04:39You'll be able to click on edit class definition if you click on this icon edit class definition, and it opens up your class
04:48You know you've done everything well

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!