startDrag and stopDrag in ActionScript

This tutorial was written for the Flash Designer software, which allows you to create flash animations in a much easier way than by using Macromedia Flash. You may get Flash Designer here.

If you need to be able to drag several objects (one at a time) in a single frame this is a good way to get it done. You can click and drag either of the rectangles below:

NOTE: Minimum Flash Designer version 5.0.17

Follow the steps below:

  1. Create a new .sfd file.
  2. Set the frame delay to "Stop".
  3. Size the frame at about 300x250.
  4. Create 2 small shapes (about 80x80) and give them different fill colors.
  5. Select one of the shapes and click Edit > Convert to Sprite.
  6. Right-click it and click "Placement Properties".
  7. Check the "Action-Script Target" checkbox and click OK (This is important! Nothing works without it.)
  8. Click the other shape and repeat the process.

Next, highlight and copy the script below, then right-click on the frame (not a rectangle) and click ActionScript in the context menu. Paste the script into the dialog and change the Sprite number to match yours (Change "Sprite5" to "Sprite3" for example) if needed.

Sprite3.onPress = function()
{
Sprite3.startDrag();
};
Sprite3.onRelease = function()
{
Sprite3.stopDrag();
};

Sprite4.onPress = function()
{
Sprite4.startDrag();
};
Sprite4.onRelease = function()
{
Sprite4.stopDrag();
};


Click the Preview button to see the results of your labor.

HINT: To drag a text object, it's easier if you place the text on top of a rectangular shape and group them, then convert them to a sprite. Otherwise, the mouse pointer has to be directly over the text to drag it. You'll "miss" if you point and click between the letters. You can make the shape the same color as your background and it won't be noticed.


Close    To Top
  • Prev Article-Flash:
  • Next Article-Flash:
  • Now: Tutorial for Web and Software Design > Flash > Flash Video > Flash Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction