Deprecated: Assigning the return value of new by reference is deprecated in /home/datafake/public_html/blog/wp-settings.php on line 468

Deprecated: Assigning the return value of new by reference is deprecated in /home/datafake/public_html/blog/wp-settings.php on line 483

Deprecated: Assigning the return value of new by reference is deprecated in /home/datafake/public_html/blog/wp-settings.php on line 490

Deprecated: Assigning the return value of new by reference is deprecated in /home/datafake/public_html/blog/wp-settings.php on line 526

Strict Standards: Declaration of Walker_Page::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/datafake/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/datafake/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::start_el() should be compatible with Walker::start_el(&$output) in /home/datafake/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::end_el() should be compatible with Walker::end_el(&$output) in /home/datafake/public_html/blog/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_PageDropdown::start_el() should be compatible with Walker::start_el(&$output) in /home/datafake/public_html/blog/wp-includes/classes.php on line 611

Strict Standards: Declaration of Walker_Category::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/datafake/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/datafake/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::start_el() should be compatible with Walker::start_el(&$output) in /home/datafake/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::end_el() should be compatible with Walker::end_el(&$output) in /home/datafake/public_html/blog/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_CategoryDropdown::start_el() should be compatible with Walker::start_el(&$output) in /home/datafake/public_html/blog/wp-includes/classes.php on line 728

Strict Standards: Redefining already defined constructor for class wpdb in /home/datafake/public_html/blog/wp-includes/wp-db.php on line 306

Deprecated: Assigning the return value of new by reference is deprecated in /home/datafake/public_html/blog/wp-includes/cache.php on line 103

Strict Standards: Redefining already defined constructor for class WP_Object_Cache in /home/datafake/public_html/blog/wp-includes/cache.php on line 425

Deprecated: Assigning the return value of new by reference is deprecated in /home/datafake/public_html/blog/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/datafake/public_html/blog/wp-includes/theme.php on line 618

Strict Standards: Redefining already defined constructor for class WP_Dependencies in /home/datafake/public_html/blog/wp-includes/class.wp-dependencies.php on line 15

Warning: Illegal string offset 'trackoutbound' in /home/datafake/public_html/blog/wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php on line 489

Warning: Illegal string offset 'trackadsense' in /home/datafake/public_html/blog/wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php on line 501

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method GoogleSitemapGeneratorLoader::Enable() should not be called statically in /home/datafake/public_html/blog/wp-includes/plugin.php on line 311
AS3 Basic Setup

AS3 Basic Setup

Post Page Rank

Writing your first Actionscript 3.0 application with Flash CS3. Here is the quick guide to get the basics set up.

First create a fla. You can name this whatever you like. Maybe myFirstApp.fla. At this point you could start writing code directly into a timeline frame however best practice is to define a document class.

The document class can be specified by entering the name of a class into the property panel for the document. This is the same place where you would specify the size of your swf. Think of a name for your document class, maybe: myFirstApp. The document class doesnt have to have the same name as your main fla there is no link between them.

By typing myFirstApp into the property panel you are telling flash to create an instance of the myFirstApp class when the fla runs.

When compiling your fla flash will go and look for the code for the myfirstApp class. It will look for a file called myFirstApp.as by searching the directory the fla is in or in the directories specified under classpath from preferences.

The next step is to create the myFirstApp.as file. This just a text file with the extension changed to .as. Place the file in the same directory as your fla.

Contents of myFirstApp.as

package
{
    import flash.display.Sprite;
    public class myFirstApp extends Sprite
    {
        public function myFirstApp()
        {
            trace("hi");
        }
    }
}

The package tag places the myFirstApp class into the root package. Which means this class wont be stored in a subfolder just in the same directory as the fla.

The myFirstApp class extends Sprite. This means that the document class as well as having any further methods and propertys that you define will also have all the methods and properties of a Sprite. The import flash.display.Sprite statement lets the flash compiler know where to look for the definition of Sprite at compile time.

Note that the myFirstApp.as class should only contain a class called myFirstApp or you will get errors.

The document class unlike other classes must extend Sprite ( or some other display class ) because the document class automatically represents the swf stage. Any movieclips instances you name and place on the stage at author time become properties of the document class and can be accessed by name from actionscript inside the class.

public function myFirstApp()
{
    trace("hi");
}

This part defines the constructor for the myFirstApp class. The constructor function for a class is a function that has the same name as the class and is called whenever an instance of the class is created. For the document class an instance is created when the swf runs. This means that the constructor is the entry point for our application and the trace statement is the first line of code to be executed at runtime. The creators of flash have borrowed these concepts from the java world.

And thats the basic set up!

Tags: , , , , , , ,

Leave a Reply