Home arrow Flash arrow Page 2 - Basic Flash ActionScript for Designers
FLASH

Basic Flash ActionScript for Designers


If you already know the basics of Flash, using tools and creating animations, you may want to add some interactivity to your work. ActionScript, an object oriented programming language built into Flash, is the key to this. Adi Reddy Mora explains the basics of ActionScript.

Author Info:
By: Adi Reddy Mora
Rating: 4 stars4 stars4 stars4 stars4 stars / 193
June 01, 2005
TABLE OF CONTENTS:
  1. · Basic Flash ActionScript for Designers
  2. · Buttons, Movie Clips, and Making them Draggable
  3. · Navigating, URLs, and Loading Images
  4. · Loading External MP3 Files

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Basic Flash ActionScript for Designers - Buttons, Movie Clips, and Making them Draggable
(Page 2 of 4 )

Buttons and Movie Clips

Buttons can be used to control movies. To accomplish this, you could directly attach actions to the button or movie clip with the on() function. Alternatively, you could write actions in the Timeline using event handler functions with instance names of button or movie clips. This second method is a better practice becuause it handles all your code at one common place instead of spreading it out over all buttons and clips.

See the example below:

// Event handler function for button with instance name
// “button1_btn” which executes the code inside the
// function when the button is pressed
button1_btn.onPress = function(){
          anim_mc.gotoAndPlay(5);
}

You can use other events in this way as well, such as onRelease, onRollOver, onDragOver, onKeyUp, etc. They also work on movie clips and their instance names.

Dragging Movie Clips

You can use the global startDrag()function or the MovieClip.startDrag()method to make a movie clip draggable. This would work with games, customizable interfaces, scroll bars, etc. A movie clip remains draggable until explicitly stopped by stopDrag() method or until another movie clip is targeted with startDrag() method. Only one movie clip at a time can be dragged in a movie.

Let us see an eample below:

// Starts dragging when “anim_mc” is pressed
anim_mc.onPress = function() {
            anim_mc.startDrag();
};
// Stops dragging when “anim_mc” is released
anim _mc.onRelease = function() {
            anim_mc.stopDrag();
};

startDrag() has two optional set of parameters that allow you to control the dragging functionality. The first is a boolean true or false parameter, which allows you to lock the dragging to the centre of the movie clip. Using "false" doesn’t lock the dragging to center, and "true" locks it to centre. The default is false.

anim_mc.startDrag(false);

The second set of parameters allows you to control the dragging to a specific area of your movie. You should specify 4 values (left, top, right, bottom) based on your movie size.

anim_mc.startDrag(false, 0, 0, 200, 400);


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 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials