Home arrow Flash arrow Page 3 - Fun Things to Do with Movie Clips in Flash MX
FLASH

Fun Things to Do with Movie Clips in Flash MX


In this final part of a four-part series, you will learn how to remove clip instances, draw in a movie clip at run-time, and more. It is excerpted from chapter 13 of the book ActionScript for Flash MX: the Definitive Guide, second edition, written by Colin Moock (O'Reilly; ISBN: 059600396X). Copyright © 2005 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 3 stars3 stars3 stars3 stars3 stars / 22
February 15, 2007
TABLE OF CONTENTS:
  1. · Fun Things to Do with Movie Clips in Flash MX
  2. · Method Versus Global Function Overlap Issues
  3. · Drawing in a Movie Clip at Runtime
  4. · Using Movie Clips as Buttons
  5. · Input Focus and Movie Clips
  6. · Building a Clock with Clips

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Fun Things to Do with Movie Clips in Flash MX - Drawing in a Movie Clip at Runtime
(Page 3 of 6 )

Flash MX introduces the ability to draw strokes, curves, shapes, and fills in a movie clip using the Drawing API, a collection of methods for drawing at runtime. The Drawing API methods are documented in the Language Reference, under the following entries:

  MovieClip.beginFill()

  MovieClip.beginGradientFill()

  MovieClip.clear( )

  MovieClip.curveTo()

  MovieClip.endFill()

  MovieClip.lineStyle()

  MovieClip.lineTo()

  MovieClip.moveTo()

The Drawing API uses the concept of a drawing pen (or simply pen) to refer to the current drawing position, similar to the drawing pen used in old line plotters. Initially, the drawing pen resides at the registration point of a movie clip. Using the drawing methods, we can:

  • Move the pen without drawing any lines or fills, via MovieClip.moveTo()
  • Draw a straight line from the pen’s current position to a specific point, via MovieClip.lineTo() 
  • Draw a curved line from the pen’s current position to a specific point, via MovieClip.curveTo() 
  • Draw a shape, via MovieClip.beginFill() and MovieClip.endFill() or MovieClip. beginGradientFill() and MovieClip.endFill().

Before, during, or after drawing, we can specify the characteristics of the drawing stroke used in any drawing operation, via MovieClip.lineStyle(). To remove a drawing, we use MovieClip.clear().

Notice that the Drawing API does not include methods for drawing shapes such as a triangle, rectangle, or circle. We must draw these using the primitive drawing methods, as demonstrated under MovieClip.beginFill() in the Language Reference.

Detailed coverage of the drawing methods is left to the Language Reference. For now, let’s take a look at a couple of examples showing the general use of the Drawing API.

Example 13-5 creates a 100-pixel–long, 2-pixel–thick, straight line extending to the right from the current clip’s registration point.

Example 13-5. Drawing a straight line

// Set stroke to 2-point
this.lineStyle(2);
// Draw the line
this.lineTo(100,0);

Example 13-6 creates a 200-pixel–wide, red square centered on the current clip’s registration point.

Example 13-6. Drawing a square

// Set stroke to 3-point
this.lineStyle(3);
// Move the pen to 100 pixels left and above the registration point
this.moveTo(-100,-100);
// Start our red square shape this.beginFill(0xFF0000);
// Draw the lines of our square
this.lineTo(100, -100);
this.lineTo(100, 100);
this.lineTo(-100, 100);
this.lineTo(-100, -100);
// Close our red square shape
this.endFill();

For a variety of interesting applications of the Drawing API (including drawing arcs, polygons, dashed lines, stars, and wedges), see:

http://www.formequalsfunction.com/downloads/
drawmethods.html


blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials