logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
European Travel
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel


dailyclick
All times in EST

Clairvoyance: 08:00 PM

Full Schedule
g
g Flash and Animation Site

BellaOnline's Flash and Animation Editor

g

Sound with ActionScript - Flash Storybook App


    With that in mind, we want the reader to be able to play the sound file immediately when the app begins. The ActionScript that plays the sound must run when the app loads. To be sure the code runs immediately, we will place the code on the first frame of the Timeline.

    Note: Any code placed on other frames of the Timeline will run when Flash enters that frame. This is one way to control the timing for your code.

  1. Add a new layer at the top of the Timeline and name it "actions". Click on the first frame of the actions layer and then open the Actions Panel. Type the following code in the blank box.

// redOrn button

redOrn.addEventListener(MouseEvent.CLICK, redOrnSound);

function redOrnSound (event:MouseEvent):void {

var jinglbellSound:jinglbell = new jinglbell();
var jinglbellChannel:SoundChannel = new SoundChannel();
jinglbellChannel = jinglbellSound.play();
jinglbellChannel = null;
jinglbellSound = null;

}

Many effects in Flash are controlled by Event Listeners, which listen for a certain event (such as a mouse click) and then run a section of code called a function. Above, we first have added an Event Listener to the redOrn movie clip that will run the function called redOrnSound.

In the reOrnSound function is the code that will play the sound file named jinglbell.

  1. The first line of code in the function creates a variable to hold the name of the sound file and a new instance of the sound.

    var jinglbellSound:jinglbell = new jinglbell();

  2. The second line of code creates a variable to hold the name of the sound channel for the sound and creates a new instance of the sound channel.

    var jinglbellChannel:SoundChannel = new SoundChannel();

  3. The third line of code associates the sound channel to the sound and plays the sound.

    jinglbellChannel = jinglbellSound.play();

    All that just to play a simple sound. Welcome to object-oriented programming.

  4. The last two lines of code set the two variables to null to save memory storage space for our app.

    jinglbellChannel = null;
    jinglbellSound = null;

Repeat these steps for the other two ornaments.

More about symbols: Symbols are the building blocks of Flash. There are three types of symbols, movie clip, button and graphic. The button symbol is different from the other two because it has a special four-frame Timeline. The other two symbol types have a Timeline like the main Timeline that we have been working on. For simple buttons, using the Button symbol and its special Timeline is sufficient. But for complex buttons such as the one we created above, we need to add ActionScript to make the movie clip function as a button.

← Back


|
Join us in the Digital Art and Design forum. | Join us in the Flash forum.


Add Sound+with+ActionScript+%2D+Flash+Storybook+App to Twitter Add Sound+with+ActionScript+%2D+Flash+Storybook+App to Facebook Add Sound+with+ActionScript+%2D+Flash+Storybook+App to MySpace Add Sound+with+ActionScript+%2D+Flash+Storybook+App to Del.icio.us Digg Sound+with+ActionScript+%2D+Flash+Storybook+App Add Sound+with+ActionScript+%2D+Flash+Storybook+App to Yahoo My Web Add Sound+with+ActionScript+%2D+Flash+Storybook+App to Google Bookmarks Add Sound+with+ActionScript+%2D+Flash+Storybook+App to Stumbleupon Add Sound+with+ActionScript+%2D+Flash+Storybook+App to Reddit



 



RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the Flash and Animation Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.

g


g features
The Motion Toolbar Tools

Apple Motion 5 - The Toolbar

Apple Motion - HUD

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor