Flasher Archive

[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]


Subject: FLASH: FYI: Stop/start button for all sounds and animations
From: Joseph Balderson
Date: Thu, 3 Aug 2000 07:46:01 +0100

Yes, I did eventually find quite an elegant solution, once I mastered the nature
of building sites with Flash as opposed to HTML. Sorry for the late reply
Aaronius.

In HTML, you have separate pages representing different parts of the site. I
quickly realized that if I built a separate scene in Flash for each page in the
site I'd have quite a large .swf file. So what I did is put all site content in
a movie clip, one frame per content page. The main scene displays this movie
clip, showing the appropriate content. When you press a menu button, it Tell
Target's the MC to switch to a different frame, thereby changing the
content/page. The user does not notice the difference, except in reduced
download time.

I am explaining this because this little trick is at the core of how the site,
and how the stop/start sounds/animations button works.


THE MENU BUTTONS

First, each menu button has a script as follows:
----------------------------------------------------
On (Roll Over)
If (/:SOUNDANI = 0)
Begin Tell Target ("/SoundR")
Go to and Stop (1)
End Tell Target
Else
Begin Tell Target ("/SoundR")
Go to and Play (2)
End Tell Target
End If
End On
On (Release)
If (/:SOUNDANI = 0)
Begin Tell Target ("/SoundC")
Go to and Stop (1)
End Tell Target
Else
Begin Tell Target ("/SoundC")
Go to and Play (2)
End Tell Target
End If
Begin Tell Target ("/textheader")
Go to and Stop (1)
End Tell Target
Begin Tell Target ("/textmotion/textbody")
Go to and Stop (1)
End Tell Target
Begin Tell Target ("/textmotion")
Go to and Stop (1)
End Tell Target
Begin Tell Target ("/movingtext/textfixed")
Go to and Stop (1)
End Tell Target
Begin Tell Target ("/movingtext/textsolid")
Go to and Stop (1)
End Tell Target
Begin Tell Target ("/movingtext/textoutline")
Go to and Stop (1)
End Tell Target
If (/:SOUNDANI = 0)
Begin Tell Target ("/movingtext")
Go to and Stop (1)
End Tell Target
End If
End On
----------------------------------------------------
"/SoundR" is the rollover sound MC, and "/SoundC" is the 'page click' sound MC.
Frames 1 are blank, and frames 2 of both MCs contain the respective sounds. On
the last frames, the actionscript layer tells the MC to stop.

There is a global variable I call /:SOUNDANI. If it is 0, all animations&sounds
are stopped. If it is 1, all animations&sounds play. The controls for whether
the sounds from the menu rollovers and clicks activate are checked directly in
the menu button instances. If the menu rolls over, but the /:SOUNDANI variable
is 0, no sound occurs. Likewise if the button is pressed.

The above script is for menu button 1/page 1, so the "Go to and Stop (1)" for
the non sound clips is to move the content MC to the appropriate content frame,
thereby eliminating the need for separate scenes for each content page.
'/textheader' is the content page header. The main scene contains the MC
'/textmotion' containing the scroll animation for up/down page buttons, within
which is contained the '/textbody' MC, which has 8 frames, one for each content
page. Each frame of the '/textbody' MC has a separate text field linked to an
external text file, allowing easy changing of site content without altering the
.fla/.swf itself. Each textfield is called 'text1' through 'text8', properties
are Multiline, Word Wrap, Disable Text Editing, Do Not Include Font Outlines (to
save on file space). On the last frame of the main scene when the content is put
up, in my actionscript layer, I put in
----------------------------------------------------
Load Variables ("page.txt", "/textmotion/textbody")
----------------------------------------------------
as script to load all text content from the external file into their respective
text fields.


At the bottom of the main scene is a moving text animation corresponding to the
content "page"; it's instance is called '/movingtext'. Within that MC are the 3
layers of text that make up the animation with corresponding MC's '/textfixed',
'/textsolid' and '/textoutline', one frame for each page, each frame of each of
the three MCs containing different library graphics.

The button script
----------------------------------------------------
Begin Tell Target ("/textmotion")
Go to and Stop (1)
----------------------------------------------------
tells the content text reset to its default state of scrolled completely up, to
prevent the user from scrolling half the way through the text of one 'page',
going to another 'page', and then returning to a half-scrolled text.

The button script
----------------------------------------------------
If (/:SOUNDANI = 0)
Begin Tell Target ("/movingtext")
Go to and Stop (1)
End Tell Target
End If
----------------------------------------------------
resets the bottom screen text animation to the beginning when a new 'page' is
displayed. If the animation was half the way through when the stop
sounds/animation button was pressed, the user will on that 'page' see the
animation 'frozen in time', but will reset to the beginning once a new 'page' is
selected, for aesthetic purposes. All this will be apparent later, when the
stop/play button is explained. You can apply this 'reset upon page change when
stopped' script for any animation.


THE STOP/PLAY BUTTON

The stop/play button is in effect two buttons within an MC. The main scene
contains the '/stop-play' MC, which has two frames - the first containing the
'stop' button, the second containing the 'play' button. Actually, there is a
frame before the first two, a control frame with the following script on the
actionscript layer:
----------------------------------------------------
Stop
If (/:SOUNDANI = 0)
Go to and Stop (3)
Else
Go to and Stop (2)
End If
----------------------------------------------------
So if the variable /:SOUNDANI = 0, which means that all sounds/animations are
stopped, the '/stop-play' MC goes to frame 3, which contains the 'play' button.
If sounds/animations are currently playing, then on to frame 2, which has the MC
display the 'stop' button.

Frame 2, actionscript layer of the '/stop-play' MC has the following script:
----------------------------------------------------
Stop
Begin Tell Target ("/logo")
Play
End Tell Target
Begin Tell Target ("/movingtext")
Play
End Tell Target
----------------------------------------------------
Frame 2 has the 'stop' button displayed, which means that snds/anis are playing.
The script tells MCs '/logo' (animated logo at the top of the page) and
'/movingtext' (containing the MC with the 8 frames corresponding to the 'page'
footer animation text) to play. You can add in any number of Tell Targets for
any number of animation or sound MCs you wish to control. The reason I have no
sound MCs in here is because all sounds on the site are either rollover sounds
or click-page sounds. If I had background music playing I would put a Tell
Target in here as opposed to the menu button instances to control that sound MC
as well. If it were a background music MC, the last frame would on the
actionscript layer instruct the MC to loop back to the second frame.

Frame 3, actionscript layer of the '/stop-play' MC has the following script:
----------------------------------------------------
Stop
Begin Tell Target ("/logo")
Stop
End Tell Target
Begin Tell Target ("/movingtext")
Stop
End Tell Target
----------------------------------------------------
Frame 3 has the 'play' button displayed, which means that snds/anis are stopped.
The script tells MCs '/logo' (animated logo at the top of the page) and
'/movingtext' (containing the MC with the 8 frames corresponding to the 'page'
footer animation text) to stop playing.

These scripts can be put on the instances of the stop or play buttons in the
second or third frames themselves, but I put them in the 'stop-play' MC frames
on the actionscript layer for clarity.

The 'stop' button in frame 2 of the '/stop-play' MC has the following instance
script:
----------------------------------------------------
On (Release)
Set Variable: "/:SOUNDANI" = 0
Begin Tell Target ("/stop-play")
Go to Next Frame
End Tell Target
End On
----------------------------------------------------
Which sets the stop-play variable to the stop position, then goes on to the next
frame in the MC, with the 'play' button.

The 'play' button in frame 3 of the '/stop-play' MC has the following instance
script:
----------------------------------------------------
On (Release)
Set Variable: "/:SOUNDANI" = 1
Begin Tell Target ("/stop-play")
Go to Previous Frame
End Tell Target
End On
----------------------------------------------------
Which sets the stop-play variable to the play position, then goes on to the next
frame in the MC, with the 'play' button.

As you can see, the first control frame with the above script is only for
initial MC loading. Once the .swf file has been loaded and the play-stop button
pressed at least once, this frame will never play again. It is to ensure that
the stop-play button has a glitch-free performance.

The reason that such elaborate measures are taken to control sound playing is
that I found 'Stop All Sounds' to be useless with button-activated sounds, as it
stops only the current sound in progress. Great for background sounds, useless
for button-activated sounds.


And that about does it for the stop/play button. Sorry I have no URL for the
site or .fla to distribute, because the client whom I have designed the site for
has not readied the full content for the site and as such has not been
officially published on the web, and until that happens I am bound by a
Non-Disclosure Agreement. But I would be happy to answer any questions you may
have.


Joseph Balderson

Aaronius wrote:

> Did you ever find a solution to this? I'm having a similar problem...
>
> Aaronius
> http://xeba.com
> --------------------------
> Get paid for all kinds of dumb stuff (better than the others):
> http://www.cashfiesta.com/php/join.php?ref=Aaronius
> ----- Original Message -----
> From: Joseph Balderson <ay527attorfree [dot] net>
> To: <FLASHmacromediaategroups [dot] com>
> Sent: Wednesday, June 07, 2000 10:37 PM
> Subject: [FLASHmacromedia] Stop/start button for all sounds and animations
>
> > I have a flash site I am building which has an animated logo and a few
> > other background elements including sound running once the intro movie
> > is finished and the main site is displayed.
> >
> > My question is: how do I create one button to stop/start all background
> > animations and all sounds? The logo and background animations are movie
> > clip objects, and the sounds are all activated by buttons, residing in
> > button objects. I figured that a dual state button would be needed,
> > something that would be a play button like (>) when all is stopped, and
> > a stop button ([]) when all animations and sound are active. But what
> > the ActionScript for something like that would be has me puzzled. I am
> > new to Flash but I am familiar with Javascript, and so I would normally
> > just plug away at it until I came upon the answer, but this is a client
> > job for which there is a time factor involved. Any insight would be most
> > welcome.
> >
> > Joseph Balderson
> >
> >
> >
> >
> > Want to learn more about Generator?
> > http://www.egroups.com/group/macromedia-generator
> >
> > -------------------------------------------
> > **To unsubscribe: FLASHmacromedia-unsubscribeategroups [dot] com (mailto:FLASHmacromedia-unsubscribeategroups [dot] com)
> > **Resource page: http://www.copfer.com/neodir/flkit.htm
> >
> >


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Full flasher archive now available online at:
http://www.chinwag.com/flasher/archive.shtml
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe or change your list settings go to
http://www.chinwag.com/flasher or email helpatchinwag [dot] com


[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]