logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Painting
Heart Disease
Horror Literature
Dating
Hiking & Backpacking
SF/Fantasy Books
Healthy Foods


dailyclick
All times in EST

Clairvoyance: 08:00 PM

Full Schedule
g
g Flash and Animation Site

BellaOnline's Flash and Animation Editor

g

ActionScript, Document Class and Flash Movie


In the last tutorial, we discussed two ways to include ActionScript in your FlashR movie. These methods had the drawback that at least some ActionScript was added to the Timeline. In an effort to move closer toward the OOP programming convention of modular code in an external file, we will now take a look at a third way to include ActionScript into your Flash movie using the Document class.

As a quick review, in the previous tutorial, we were using ActionScript to draw a red circle on the stage. We had placed this code in an external file and added an include statement on the Timeline to tell Flash to call in the external code.

With this next method of associating our ActionScript with our Flash movie, we will remove all code from the Timeline and use the Properties Inspector to declare a Document class which will connect our Flash movie to the external code. (A Document class is a top level class or top level object that is created when your Flash movie is loaded into the Flash Player.)

Our first step is to remove the include statement from the Timeline.

  1. Open your RedCircle.fla file into Flash.

  2. Select the first frame on the Actions layer and open the Actions panel. Remove the include statement and close the Actions panel.

    Now we will declare our Document class from the Properties Inspector. This is our new way of associating our ActionScript with our Flash movie.

  3. With the Selection tool, click on the stage to display the Document properties in the Properties Inspector. At the bottom of the panel, you will see a text input box where you can enter the name of your new Document class. In this dialog box, enter the name of our external ActionScript file without the .as extension. If you remember, we called this file DrawCircle.as in the previous tutorial. So you will enter "DrawCircle" in the box. Flash may notify you that it will automatically create this new Document class for you. Just click OK.

    Note It is customary for the first letter in the name of a Document class to be an upper case letter.

    This declaration of a Document class is all we need to do to associate our external ActionScript file with our Flash movie. Now we need to work on that external file. We need to add a few more lines of ActionScript code to the existing code that draws the red circle on the stage. Open the DrawCircle.as file into Flash and replace the code that is there with the following code.

    package
    {
    import flash.display.Sprite;
    import flash.display.Shape;
    public class DrawCircle extends Sprite
    {
    public function DrawCircle()
    {
    var myCircle:Shape = new Shape();
    myCircle.graphics.lineStyle(2, 0x000000);
    myCircle.graphics.beginFill(0xff0000);
    myCircle.graphics.drawCircle(100, 200, 50);
    myCircle.graphics.endFill();
    addChild(myCircle);
    }
    }
    }

    This new code first imports the Sprite class and then the Shape class which we need to draw our circle on the stage. We did not need to do this when our code was on the Timeline. But when our code is external to the Flash movie, we must first import the Shape class before we can use its predefined Graphics property and methods to draw on the stage. Test your movie and you will still get the red circle drawn on the stage.




Add ActionScript%2C+Document+Class+and+Flash+Movie to Twitter Add ActionScript%2C+Document+Class+and+Flash+Movie to Facebook Add ActionScript%2C+Document+Class+and+Flash+Movie to MySpace Add ActionScript%2C+Document+Class+and+Flash+Movie to Del.icio.us Digg ActionScript%2C+Document+Class+and+Flash+Movie Add ActionScript%2C+Document+Class+and+Flash+Movie to Yahoo My Web Add ActionScript%2C+Document+Class+and+Flash+Movie to Google Bookmarks Add ActionScript%2C+Document+Class+and+Flash+Movie to Stumbleupon Add ActionScript%2C+Document+Class+and+Flash+Movie to Reddit



 



RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the Flash and Animation Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2013 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.

g


g features
Ken Burns Effect In Motion - Record Keyframes

Ken Burns Effect In Motion 5 - Set Up

Animated Title in Motion

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2013 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor