Adding audio to dynamically created buttons
Video: Adding audio to dynamically created buttonsOne issue you might run into is how to add sound to buttons that are created with ActionScript and that's what's going on here with this portfolio, because I want to add just some click sounds when the user clicks on any one of these portfolio items. So that's what I want to do. I am going to close this SWF and I am going to go to the Timeline. So within this portfolio.fla, I need to open up that ActionScript layer, this very first frame.
Viewers: in countries Watching now:
Flash and ActionScript are ideal for creating flexible, easily updatable web sites that are both unique in design and small in file size. In Creating a Portfolio Web Site Using Flash CS4 Professional, Adobe Certified Instructor Paul Trani shows how to exploit Flash to create a web site that showcases work to clients and prospective employers. Find out how to add dynamic navigation, animation, and video to a page, and how to load, sort and display XML that enables portfolio content to be updated without opening Flash. This course is designed to take your existing tweening skills and gotoAndPlay code and walk away with a fully functional Flash site. Exercise files accompany the course.
- Optimizing and publishing a Flash web site
- Designing a professional photo or video portfolio
- Adding button interactivity
- Adding functionality to portfolio thumbnails
- Displaying content with XML
- Adding audio to portfolio presentations
Adding audio to dynamically created buttons
One issue you might run into is how to add sound to buttons that are created with ActionScript and that's what's going on here with this portfolio, because I want to add just some click sounds when the user clicks on any one of these portfolio items. So that's what I want to do. I am going to close this SWF and I am going to go to the Timeline. So within this portfolio.fla, I need to open up that ActionScript layer, this very first frame.
I am going to go to Window>Actions. So here's where all my code is written and right down here when you click on any one of the images, it's going to fire off this function. This is where I need to add my audio, but I am going to start off at the very top. Right up here at the top, I am just going to do two forward slashes so I can add a comment and I am just going to type in SOUND. This is where my sound item is going to go. It's going to be a variable, so var clickSound is what I am going to make.
I'm telling Flash that it's a sound and here's where I create a new sound from the Sound class. All right. So here's where I create this variable called clickSound from this Sound class. But there's nothing in it yet. I actually need to do a URL request and I need to go out and grab that sound and then put it inside of this variable. So what I am going to do is I am going to go out to my desktop into my Assets folder. I am going to click on sound and this is the file that I want to play.
So I am going to copy this click.mp3 and I am going to move it into the folder that I am working in. So I am actually going to create a new folder just so I can keep everything organized and I am going to call this sound. And in this folder, that's where I am going to paste that click.mp3. So again, this is the portfolio.fla that I'm working in. So If I go back to it, for new sound what I need to do is I need to type in new URLRequest, an open parenthesis, open quote, sound, forward slash, click.
So it's in the sound folder, click.mp3 is what I am after. I need to close that quote and close that parenthesis, so make sure you have two down here at the end. But in essence, what's happening is it's taking and grabbing that mp3 and putting it right in this variable. So I am actually going to copy this variable, scroll down to where I want to use it, right inside of this function. So about Line 52 right now, I want to paste in that clickSound variable. All I need to do is type in a period and type Play and open and close parentheses. End it with a semicolon. All right.
So that's all I need to do, but let's go ahead and test this out. Now as I click on these buttons, you should hear a click sound. Great! It works like a charm, works great and what's happening is I've made this sound variable that grabs this click.mp3. So I do need to remember to make sure I always have this click.mp3 in this sound folder in relation to where the SWF file is.
So if I upload this site to a web server, I need to make sure this mp3 travels with it. But it's pretty easy to implement, took me two lines of code and works great.
Find answers to the most frequently asked questions about Creating a Portfolio Web Site Using Flash CS4 Professional .
Here are the FAQs that matched your search "" :
- Q: While following along with the course, I encountered the following error in Flash CS4:
1120: Access of undefined property content_mc.What is causing this error?
- A: Flash is looking for something (the content movieclip) with the instance name “content_mc” but it is not finding it. Select the content movieclip on the stage. In the Properties panel give it an instance name of “content_mc”. Make sure there are no spaces before or after. That should resolve the error.
- Q: What is the best strategy for integrating 720/60P HD video into a website? Would creating a blank page that opens in full HD resolution be the best way to view the full quality of the HD video file?
- A: A video file that large would just be unreasonable for most users to open. These settings are a good place to start: 600x400is
Bitrate level: 1,000kbps
Bitrate Encoding: VBR These are just recommendations, and can be modified to preference. Also keep in mind that in Flash, one of the buttons that can be added is a full screen button, which is part of the skins.
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.