Basic AS3 Tutorial

From FDT Documentation

Revision as of 04:44, 14 September 2010 by Aklement (Talk | contribs)
Jump to: navigation, search

Beginning with FDT4, creating AS3 projects has never been easier. FDT 4 now features powerful template management that are designed to help developers get up and running in a flash.

If you haven't installed and created your workspace yet, check out the Installing and Running FDT tutorial to guide you through the process.

Once you have FDT open, you have a few different ways of creating a new project. You can click "Create new Flash Project" via the Welcome Screen, right click in the Flash Explorer and choose 'New Flash Project' or choose 'New Flash Project' from the 'File>New menu' ( OSX ). Right away you'll see FDT's new Project Template Wizard open. Give the project a new name, 'AS3 Project' will work fine, and let's stick with choosing 'Empty AS3 Project'. When a valid project name has been added and a project template has been selected, the 'Finish' button will highlight. Click finish to continue.

Now we can see our project FDT created for us within the Flash Explorer. Click on the little arrow next to the project icon to expand it's contents. Here you can see a basic FDT project setup and see what our 'Empty AS3 Project' template has setup for us:

To run and build a Flash Project, FDT only needs one file. If you're familiar with Flash Authoring or Flash Builder, this is like creating your 'Document Class' or 'Main' class. Create this file by right clicking on the 'src' folder and choosing 'new>AS Class'. What pops up is FDT's New ActionScript Class Wizard. Once here, we'll just fill in a valid class name, 'Main' is pretty standard, and then define the superclass by clicking on the 'Browse...' button. You can use either 'Sprite' or 'MovieClip' for superclass and unless you have a special reason, Sprite will work fine. Filer the Sprite class by beginning to type 'Sprite' within the search input box on the top and when you see "Sprite - flash.display" click on that and hit the 'OK' button. After filling in a valid Class name and a valid superclass to extend, hit the 'OK' button.

FDT will now create a new Class for you automatically and open it within the Editor View. If some reason it didn't open for you, double click on the 'Main.as' file within the Flash Explorer. With our 'Main.as' file open, let's create a simple red circle on the screen and then run our file.

Within the constructor of your class, add this bit of code to add a red circle to the stage.

var circle : Shape = new Shape(); circle.graphics.beginFill(0xff0000); circle.graphics.drawCircle(150, 150, 100); addChild(circle);

To quickest way to launch your application is to right click on the Main class within the editor, and select Run As>FDT SWF Application. FDT will being the build process, as can been seen in the Console View, and when complete FDT will launch the External SWF Viewer that runs our .swf with the TextField on the Stage displaying ‘hello world’.

With compilation successful, FDT will have created a .swf in your Output Folder, bin by default and created a Launch Configuration located within the folder .settings>launch.

Congratulations, you’ve built your first FDT application. From here, you’ll probably want to learn more about editing Launch Configurations and Compiler Options such as SWF size and background color.

After viewing your .swf, close the External SWF Viewer and confirm your .swf was created by opening up your 'bin' output folder and looking for 'Main.swf'

FAQ

  • Q: How Do I change .swf settings like background color or size?
  • A: Check out the Compiling and Viewing Projects tutorial to learn about different ways to compile and view your Flash Applications
  • Q: Does my class need to be named 'Main'.
  • A: Not at all - any legal class name works. FDT has a very powerful and flexible way of building and running your applications. Check out Compiling and Viewing Projects for more info.
  • Q: Why is my output swf names 'Main.swf' and why is my launch configuration names 'Main'.
  • A: When clicking on a Class and choosing 'Run As...' from either the Editor or the Flash Explorer - if FDT doesn't detect that a launch configuration already exists for that file, FDT will create a new one. The new launch configuration created will have the same name as the Class that was selected when choosing 'Run As...' or 'Debug As...'
  • Q: Why is it that when I click on my project within the Flash Explorer and then go to the Run Menu, I don't see my 'Main' class, '(no launch history)' or I see 'Run As>FDT SWC Library'
  • A: FDT works differently than other IDEs. It uses Launch Configurations and doesn't force you to hardcode any settings. This includes compiler options, your 'Main' class or the name of your output .swfs. You can even create many different launch configurations for one project. Learn more with the Understanding Launch Configurations tutorial.
Get FDT5