- Home
- Tutorials
- Flash
- Intermediate
- Fast Forward and Rewind for a Jukebox for MX 2004
Fast Forward and Rewind for a Jukebox for MX 2004

Page 1 of 1
Dreamer
This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via support AT actionscript DOT org.
View all articles by DreamerWritten by: Dreamer
Difficulty Level: Intermediate.
Example (256kb) This tutorial will show you how to make a simple yet functional 'fast forward' and 'rewind' buttons for a jukebox. If you don?t know a lot about Actionscripts, don?t worry, I?ll guide you along the way and try to explain everything. However, I do recommend that you know a little actionscripting. The scripting for this doesn?t require any looping of a time line but rather the bulk of the scripts will be placed on the actual 'TextArea' component. Let?s begin. 1. Construct yourself a very simple jukebox with the following components:
- a 'stop' button
- 'play' button
- 'fast forward' button
- 'rewind' button
- a TextArea box
baseVolume=15;
mySound=new Sound(_root); mySound.attachSound("did");
mySound.setVolume(baseVolume * 2);
on(release) {
mySound.stop(); }
on(press) {
mySound.stop(); box.hold=0;
} on(release) {
mySound.start(0,1); }
onClipEvent(load) {
alpha=0; }
onClipEvent(enterFrame) {
this.text=_root.mySound.position; if(alpha==1) {
_root.mySound.stop(); hold=_root.mySound.position*.001;
hold++; _root.mySound.start(hold,0);
} if(alpha==2) {
_root.mySound.stop(); hold=_root.mySound.position*.001;
hold--; _root.mySound.start(hold,0);
} }
The code inside the curly brackets, alpha=0; is a variable I created called alpha which has a value of 0. This code, alpha=0; plays a very important role in controlling the fast forward and rewind abilities.
The second half of the code, onClipEvent(enterFrame) loops as long as its MC/component is under the play head. So it will continually execute the lines of code within its curly brackets.
The code, this.text=_root.mySound.position; takes the current position of the mp3 and sends it to the TextArea as text. In this.text the this refers to the TextArea since the code is on it and text refers to the TextArea identifier that enables text to be viewable. Thus, you will be able to see the constant position of the mp3 in milliseconds.
The next lines of codes are basic if statements which I won?t go into detail. But basically, it states if alpha is equivalent to 1, then it will execute the 4 lines of code inside its curly brackets.
Inside those brackets are the following:
- _root.mySound.stop(); tells the mp3 to stop.
- Then there is, hold=_root.mySound.position*.001; which is yet another variable I called, hold that has a value of _root.mySound.position. What this does is it will grab the position where the mp3 has stopped in milliseconds. Then the *.001 will multiply the grabbed milliseconds and equate it into seconds; (i.e. 20,000 milliseconds x .001=20 seconds). The reason for the equation to convert the milliseconds into seconds is because later, you will be grabbing the stored position of the stopped mp3 for further manipulation using the mySound.start(); (remember that mySound.start() measures starting points in seconds whereas, mySound.position grabs the position in milliseconds).
- Then the variable hold will increase (++).
- Finally, _root.mySound.start(hold,0); will execute, which will restart the mp3 from the last position that it was stopped. The whole first if statement executes the fast forward ability while the second if statement does the same thing for the rewind (hold--).
on(press) {
if(_root.mySound.position>.001) { box.alpha=2;
} }
on(release) { box.alpha=0;
}
The box.alpha=0; states that on release of the button (on(release)), it will default the alpha back to 0 which will stop executing the if statements on the TextArea component. Pretty strait forward isn?t it?
7. Finally, if you click on the 'fast forward' button, you will find the same code as the one above with the exception that box.alpha=2 is now box.alpha=1. This just executes the other if statement on the TextArea component and thus enabling the fast forward ability. At last, you have finished all the Actionscripts and hopefully there?s no errors. Of course, these codes can be greater refined to have much better and smoother control over the mp3 but, this tutorial just covers the fundamentals. Test it out and see if it works. Enjoy!
Spread The Word
Related Articles
1 Response to "Fast Forward and Rewind for a Jukebox for MX 2004" 
|
said this on 03 Jan 2012 10:28:06 PM CDT
I really appreciate free,
|


Author/Admin)