Flash
  Home arrow Flash arrow Page 3 - Fun Things to Do with Movie Clips in Flash...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

Fun Things to Do with Movie Clips in Flash MX
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 21
    2007-02-15

    Table of Contents:
  • Fun Things to Do with Movie Clips in Flash MX
  • Method Versus Global Function Overlap Issues
  • Drawing in a Movie Clip at Runtime
  • Using Movie Clips as Buttons
  • Input Focus and Movie Clips
  • Building a Clock with Clips

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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

    More Flash Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "ActionScript for Flash MX: the Definitive...
     

    Buy this book now. This article 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). Check it out today at your favorite bookstore. Buy this book now.

    FLASH ARTICLES

    - Decorator Pattern
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications
    - ActionScript in Flex Applications
    - A Closer Look at Apollo`s File System API
    - Using the File System API
    - ActionScript 101
    - Flash Buttons
    - Advanced Flash Animation
    - Creating Your First Animated Movie with Flas...
    - Flash: Building Blocks






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT