Macromedia Flash MX Tutorial - Digital Slider
Name: Digital Slider
ID = Version: SWF file size = 712 Bytes Posted: 1/16/03
Level: Intermediate
Primary Focus: event handler method
Secondary Focus: dragging movie clip
Approach: All the ActionScript is placed in one frame.
Flash Movie
ActionScript
// Macromedia Flash MX Tutorial 1
// Author: Bruce L. Bird, MINDdrops.com
// Date: January 16, 2003
// Digital Slider
//Moving slider causes continuous change in digital reading
//Initial Values
stop();
//Click and Drag Slider
// "slider" is the instance name for dragable red dot movie clip
_root.slider.onPress = function() {
this.startDrag(false,100,196,250,196);
};
_root.slider.onRelease = function() {
this.stopDrag();
};
_root.slider.onReleaseOutside = function() {
this.stopDrag();
};
// Place position of slider in dynamic text box
// with variable name: reading
slider.onEnterFrame = function() {
// Normalize slider position so digital reading varys from 1 to 100// This slider's x position varies between 100 to 250 pixels
sliderRange = 150;
normalizedReading = 100*(slider._x - 100)/sliderRange;
// Now need to adjust so only get integer readings
integerReading = Math.round(normalizedReading);
reading = integerReading;
// The digital reading can now be used to manipulate other objects
// This example demonstrates changing the size of a triangle.
_root.triangle._xscale = 10+4*reading;
}
Comments
All of the ActionScript sits in frame 1 of the Action layer in the main (_root) timeline.
In ActionScript the syntax
movieClipInstance.onPress = function( ) { ..... }
is sometimes called an "event handler method" which is not the same as "event handler" (Franklin, page 73). Other writers use the terms "anonymous function" to distinguish this syntax from "named functions" (Chun, page 99; Drol, page 95)
References
Chun, Russell, Macromedia Flash Advanced for Windows and Macintosh, Peachpit Press, 2003
Drol, William, Object-Oriented Macromedia Flash MX, Apress, 2002
Franklin, Derek, and Jobe Makur, Macromedia MX Advanced Training From The Source, Macromedia Press, 2002
2002-7 All rights reserved. MINDdrops.com