Skip to main content
dstx
Inspiring
December 29, 2008
Answered

Flash movie control buttons

  • December 29, 2008
  • 24 replies
  • 3026 views
In Flash 8, I want to add a set of buttons from button library to bottom left of my movie
(begin, stop, pause, play, end) that are visible entire duration of movie.
What is best way to create such action? With event handlers?
Do I put each button on a separate layer and add frames from beginning to end of movie ?
Or can all buttons be on same layer?
And how do I find/write actionscript code that will control entire movie from any frame for each action: go to beginning or end, stop, pause, or play?
This topic has been closed for replies.
Correct answer clbeech
dstx - you're welcome :)

nice kg - that's an efficient toggle setup!

just for fun, how about :D

pauseBtn.onRelease = function() {
(toggle = (toggle) ? false : true) ? stop() : play();
}

24 replies

kglad
Community Expert
December 29, 2008
(wanna bet?)
dstx
dstxAuthor
Inspiring
December 30, 2008
what do you mean "wanna bet"? if you have a better suggestion, please post instructions, otherwise do not "advertise" in my post.
clbeech
Inspiring
December 29, 2008
what ihong7 is saying above is to 'attach' code to each button using the 'on(release)' event handler. in order to do so, you would select one of your buttons, then open the 'actionscript' panel, which is where one writes code. however the above method is not recommended, since attaching code to objects is not considered to be 'good' practice and has been eliminated in more recent versions of AS. instead, one should place your codes on the timeline, to do so, create a new layer called "actions", you will use this layer for all of the necessary code. to enter code, select the first frame of the layer 'actions' and open the actions panel and type in the codes needed. 'actionscript' is the programming language used in Flash and under Flash8 it is actionscript 2.0 - i would also recommend doing some reading in the Flash Help documentation, which will give you a basis to use Flash and code effectively.

it is fine for the buttons to all be on the same layer, but you will need to give each of them an 'instance name'. to do so select one of the buttons you've placed on the stage, look in the properties panel, on the left side you will see a input field that says <instance name>, type the individual name of the button into the field. this will allow you to 'point' to the instance with your codes.

to create a 'event handler' that your buttons will respond to you need to specify which event you are using. in this case you are basically going to use the 'onPress' or 'onRelease' handler(s) - personally I prefer the onPress for a few different reasons. so to get your button to 'hear' the click you would use this syntax:

myButton.onPress = function() {
trace('myButton has been pressed');
}

the 'trace' statement above is only for demonstration and will cause the text to be displayed in the output panel, this is an example of 'how' you can get the event to respond to the click of the mouse - also in the code above we are 'assigning' the event handler to the button with the instance name of 'myButton' - for each button that you have named and is on the stage, you will need to 'point' to that instance using the instance name of each button.

now, you wish to use the buttons to control the movie playback it appears, so you will need to place code within the event handler's function in order to achieve each of the actions you want the button to perform. to 'stop' the playhead at the current point in the timeline you use the method - stop(); - and to play the timeline from the current point you use the method - play(); - so for instance:

myStopButton.onPress = function() {
stop();
}

myPlayButton.onPress = function() {
play();
}

to 'pause' the timeline playback, use the stop method - if your wish for the stop button to do something else, you will need to apply a different code.

to cause the playhead to move to a different part of the timeline - for instance going to the 'end' of the movie - you can use the method: gotoAndStop(); - but you need to indicate 'where' to go to, we can use either a frame number, or a label (another subject) however in this case you can also use another property of the MovieClip class, as below:

myEndButton.onPress = function() {
gotoAndStop(_totalFrames);
}

the property '_totalFrames' will return a number that represents the last frame of the Main timeline. to go to the beginning or restart the Movie use the number 1 as it is the first frame: gotoAndStop(1);

this should get you going for now :)
dstx
dstxAuthor
Inspiring
December 30, 2008
What about just skinning the movie with the FLV Component?
I created new layer "Controls" above all other layers. Then dragged and aligned the FLV Playback - Player 8 component to that layer and set Parameters in Component Inspector to -
autoPlay: false, autoRewind: false, autoSize: false, bufferTime: 0.1, cuePoints: none, isLive: true, maintainAspectRatio: true, skin: ClearExternalAll.swf, skinAutoHide: false, totalTime: 0, volume: 100

When I Test Movie in Flash, it plays fine and timing is correct, but there's a space below movie above controller.
When I upload to server and test in browser, controller placement is immediately below movie as should be, but audio autostarts and plays ahead of video, progressively worse toward end of movie.
Also video loops, there's a green dashed progress bar which I'd like to delete, no stop, pause, rewind, or end buttons, only volume and play buttons which don't work .

See work in progress: http://DStall.com/Moon.php
dstx
dstxAuthor
Inspiring
December 29, 2008
I don't understand. Can you be more specific?
I have all buttons on same layer with all frames filled for entire length of movie so all buttons are visible continuously throughout the movie.
Now, how do I click on any of the five buttons, actionscript??? What does that mean?
Inspiring
December 29, 2008
put a button on the main scene, click the button, action script:

on(release) {
play();
}

and so on.

you make a new time line that have the buttons visible thru out the movie