Flash
  Home arrow Flash arrow Page 3 - Flash MX Prototyping Basics
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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
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

Flash MX Prototyping Basics
By: David Millington
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2004-06-09

    Table of Contents:
  • Flash MX Prototyping Basics
  • A Side Note on Paths
  • Dealing with Time
  • Self Containment

  • 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


    Flash MX Prototyping Basics - Dealing with Time


    (Page 3 of 4 )

    When dealing with prototypes, you will often want actions to take place after an event or amount of time has passed. Let's deal with both, starting with events. The example uses a movie that reacts to the mouse being over it or not. To be specific, the movie plays forward when the mouse is not over it. When the mouse is moved over the movie, it plays in reverse. 

    MovieClip.prototype.alternateDirection = function() {
     // Set the initial direction to play forward
     this.playForward = true;
     // Set mouse events up to control the play direction
     this.onRollOver = function() {
      this.playForward = false;
     };
     this.onRollOut = function() {
      this.playForward = true;
     };
     this.onEnterFrame = function() {
      if (this.playForward) {
       this._currentframe == this._totalframes ? this.stop() : this.gotoAndStop(this.nextFrame());
      } else {
       this._currentframe == 1 ? this.stop() : this.gotoAndStop(this.prevFrame());
      }
     };
    };
    // Set the prototype off
    myMovie.alternateDirection();

    In this prototype an internal variable is set which controls the direction the movie plays. If you look toward the beginning of the code, you will see the onRollOver and onRollOut events being attached to the movie. These are a couple of the mouse events that you can link to your movie clips. Notice how they look very similar to prototypes? Using the same prototype you can see an example of time control via the onEnterFrame event handler. This runs continually throughout the movies life span or until the handler is deleted. All that happens here is that every frame the movie checks whether the playForward variable is true or false. You may be wondering what the strange notation is within the if and else clauses. It's another way of writing conditional statements; here's a translation:

    this._currentframe == this._totalframes ? this.stop() : this.gotoAndStop(this.nextFrame());
    if ( this movies current frame = the last frame ) stop it otherwise goto the next frame and stop.

    More Flash Articles
    More By David Millinton


     

    FLASH ARTICLES

    - 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
    - Building Preloaders
    - Fun Things to Do with Movie Clips in Flash MX







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway