navigate site menu

Become a member and get unlimited access to every course in the library. Try it free for 7 days

Flash CS4 Professional Audio Techniques

Flash CS4 Professional Audio Techniques

with Todd Perkins

 


Flash CS4 Professional Audio Techniques shows how integrating audio into Flash projects can create a more engaging and interesting viewer experience. Instructor Todd Perkins dives deep into the details of manipulating audio in Flash using ActionScript 3.0. He demonstrates how to monitor a song's playback progress, display this information for viewers, and create a viewable playlist for multiple songs using XML data. Through the course of the tutorials, Todd creates an audio player for the web, complete with sharing capabilities. Exercise files accompany this course.
Topics include:
  • Playing and pausing audio in a created player class
  • Controlling audio progress and showing it in a text field
  • Loading XML playlist data into the final player
  • Animating a volume slider and using effects to add depth
  • Making Flash applications sharable
  • Viewing the finished player and taking it for a spin

show more

author
Todd Perkins
subject
Audio, Web, Projects
software
Flash Professional CS4
level
Intermediate
duration
2h 18m
released
Aug 18, 2009

Share this course

Ready to join? subscribe


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:00(Music plays.)
00:07Welcome to Flash CS4 Professional Audio Techniques.
00:11I am Todd Perkins and I will be walking you through this title, teaching you
00:14how to use object-oriented programming techniques to manipulate audio in Flash Player.
00:21We will look at how to load external sound files, how to control their playback.
00:26We'll work with building an XML playlist, controlling sound volume, sound
00:34progress and we will even talk about how to share your application over the web.
00:38We have a lot to learn here, so let's get started.
Collapse this transcript
Using the exercise files
00:00If you are a premium subscriber to Lynda.com or if you purchased this title on a disk,
00:05you have access to the exercise files for this title.
00:09The exercise files for this title are organized by chapters.
00:14Each chapter is organized by movie.
00:20For each movie, you will have the starting files as well as the files that I end up with.
00:27That way, in case something goes wrong in your code, you can have the
00:30final files as a backup.
00:35Generally, all chapters are organized in that way.
00:39The last chapter, however, just has all the files in there by itself.
00:45As we are going through the title, you will see what files you need to work
00:48with on your screen.
00:51If you don't have the exercise files, you can still follow along.
00:54I will show you what you need to do to set up your FLA and ActionScript files in
00:59the way that you need so you can follow along with every step.
01:04So let's get started.
Collapse this transcript
Prerequisites
00:00Since this is a pretty advanced title, you should come into it knowing a lot
00:05about Flash and ActionScript.
00:08In this movie, we will talk about the prerequisites for this title.
00:11You should be familiar with the basics of Flash, equivalent to that taught in
00:15Flash CS4 Essential Training.
00:17So you should be very comfortable with the interface.
00:20You know how to navigate through movie clips and the Library, and the
00:23Properties panel, etcetera.
00:25You should be familiar with publishing Flash files including creating SWFs and HTML files.
00:31You should have some basic ActionScript training at the very least.
00:36ActionScript 3.0 for designers is a title that's designed to teach programming
00:41to people that are new to programming.
00:44So if you don't know any ActionScript at all, I suggest starting there.
00:48Finally, we are going to be doing a lot of object-oriented programming in this title.
00:53If you don't know object-oriented programming, I highly recommend watching my
00:57title in object-oriented programming in ActionScript 3.0.
01:02So if you feel comfortable with Flash CS4 and ActionScript 3.0, you are ready to
01:07start working with audio in this title.
Collapse this transcript
Course overview
00:00Throughout this title we are going to look at making all of the individual
00:04elements of a full featured audio player.
00:07Here is an example of some of the features that you are going to learn.
00:13You will learn how to play an external audio file.
00:15(Music Playing)
00:17You will learn how to manipulate a song's volume.
00:22(Music Playing)
00:29Take sound wave data from a song and display it visually.
00:35(Music Playing)
00:37And add elements to share your songs over the web.
00:38We will also talk about how you can put links to buy songs through iTunes.
00:49By the time you are done with this title and you will have all the skills
00:52that you need to add object oriented programming audio elements to your own applications.
Collapse this transcript
About the music
00:00The music for this title has been provided by a friend of mine and fellow and
00:04Lynda.com author Garrick Chow.
00:08He is in a band called The Jellybricks.
00:10He has provided one of their full-length albums for us to work with.
00:15So I thought I would take a movie to thank him for providing that and show you
00:18guys where you can find more information about his band.
00:23The band is called The Jellybricks, and their website is thejellybricks.com.
00:27So, you can go there and find all of the information about the band that you need.
00:31So, thank you very much Garrick, we are glad to be using your music in this title.
Collapse this transcript
1. Audio Basics
Setting up your FLA and other files
00:00Before we start creating our music player, let's take a look at how to organize
00:04your FLA file and the other files that you will be working with.
00:09In the exploring-fla folder, I have a folder called start.
00:13That's where the files are that you will be working with for this exercise.
00:16I have a music file called 01 Eyes Wide.mp3.
00:20If you don't have the Exercise Files, you can use any MP3 file here.
00:25In addition to that file, I have an FLA file called player.fla, which we
00:29will explore later on.
00:31And a folder called com.
00:33Note that it is all lowercase.
00:35Inside of the com folder is a folder called lynda, also all lowercase.
00:39Inside of the lynda folder is a folder called audio, also all lowercase.
00:44And inside of there is a lone action script file Player.as, note that it starts with a P.
00:50If you don't have the Exercise Files, now it is probably a good time to create that file.
00:54So, create Player.as and just save it in that folder.
00:58Let's take a look at player.fla in Flash.
01:02This file is actually pretty simple, on the stage here there is only one
01:06layer and one frame.
01:07If I select the artwork on that layer, you will see that it's a single movie clip.
01:12I will expand the Properties panel and we will take a look.
01:15Note that it is called player_mc.
01:18And if I double-click that movie clip, I can enter its Timeline.
01:23Inside its Timeline, you will see three layers.
01:26There is the pause layer, the play button layer, and the background layer.
01:30The pause layer contains a movie clip called pause_mc.
01:36The movie clip is actually just a simple Bitmap graphic of a pause button.
01:41I will zoom in a little bit so you can see it. It is right there.
01:46It looks kind of funky because the play button is right behind it.
01:49But it is just a Bitmap graphic, and you don't have to use a Bitmap graphic.
01:52You can just make your own little quick vector graphic if you would like.
01:55So, back to the player, I will hide the pause button, and then double-click the
02:01play button to enter its Timeline.
02:04The play button is also a simple Bitmap graphic.
02:07Back to the player movie clip, note that the play button has an instance name of play_mc.
02:13The background is actually just a rectangle with a Bitmap fill.
02:18In other words, I imported a Bitmap image I created in Photoshop, I drew a
02:22rectangle and using the Fill Color menu I selected the Bitmap that I imported there.
02:30And that's really all there is to this FLA file.
02:33So, once you have your FLA file setup, you are ready to start writing the code for our application.
Collapse this transcript
Creating the Player class
00:00In this movie we will look at creating the main ActionScript class for our audio player.
00:05The first thing I want you to do is go to the Library, right-click or Ctrl+Click
00:10the Player movie clip and choose Properties.
00:15Note that I have this movie clip Exported for ActionScript, and the Class I am
00:20using is com.lynda.audio.Player.
00:24If your player ActionScript file is just a blank ActionScript file, then Flash
00:29is going to get mad at you for doing this.
00:32If your player Class file does not have any code in it yet, this may not work.
00:37So, you may want to write the code and then come back to Symbol Properties, and
00:41type in the name here.
00:43Notice it's the fully qualified class name, which includes the package
00:46com.lynda.audio, and just as a refresher the package name corresponds to
00:52that folder structure.
00:53So, there's the com folder, inside of the com folder is lynda, inside of the
00:57lynda folder is the audio folder, which contains the file Player.
01:01So, I am going to click OK.
01:05So, once you have done that, go over to Player.as.
01:08Now, I have already started building this Class file and I am just going to get
01:12a little bit more room here by minimizing the other panels.
01:15Now, I just wrote the basic skeleton of a Class file.
01:18If you don't have the Exercise Files, just copy the code I have here.
01:22Make sure to declare the com.lynda.audio package, and import the main classes we will be using.
01:29All the display classes, all the event classes, all the geometry classes
01:35which is flash.geom, media classes for the sound, and the net classes for the URL request.
01:41I have my class declaration here.
01:44I am extending the MovieClip class, and inside of there I have my
01:49constructor defined.
01:50So, let's start defining a few properties.
01:53In order to work with sound, you need a sound object and a sound channel object.
01:58So, first I will create a public property.
02:00So, public var channel, datatype it to a SoundChannel.
02:04Remember the SoundChannel class is used to play the sound, and stop a sound, to
02:11get the sounds position and everything.
02:13The sound class basically just loads the sound.
02:17Another public property called sound, datatype it to an instance of the Sound class.
02:23And one more property, this will also be public and we will call this
02:27resumeTime, datatype it to a Number and set it's initial value to 0.
02:33This will represent the time in milliseconds that the file will resume at when
02:39you click the play button.
02:40So, 0 would be the very beginning of the song and a thousand would be 1000
02:46milliseconds or 1 second into the song.
02:48We will look at that in a little more detail later on.
02:53Inside of the constructor, we are going to set play_mc.buttonMode = true.
03:00So, buttonMode = true, same thing for pause_mc.
03:08Remember that button mode is what makes a movie show the hand icon when you roll over it.
03:13And then finally what we will do is set the pause_mc to hide at the beginning.
03:19So, we won't have the music playing until the person clicks the play button, and
03:22when the play button shows I don't want the pause button to show and vice versa.
03:26So, pause_mc.visible = false.
03:32And there's the basic setup for our Class.
03:34Now, just to make sure everything is working, just save this file and test the
03:38movie straight from the class file as long as your Target is set to the proper
03:42FLA file you should be good.
03:44Test the movie, and you should see the hand cursor when you roll over the play
03:48button, and no file should play yet.
03:51All right, looks like everything is working properly.
03:53So now our player class is officially set up.
Collapse this transcript
Playing audio
00:00Now that our player class is set up, we can take a look at loading an external
00:04sound file and playing it in the Flash Player.
00:08Now, this may be a review for you but it's good to go over it again just as a refresher.
00:13The first thing I am going to do is at the bottom of the constructor method, I
00:17am going to type play_mc. addEventListener and we will add a MouseEvent.CLICK
00:24listener, so MouseEvent.CLICK and we will run a method called playSong.
00:33And now I'll define a public method called playSongs.
00:35So, public function playSong, we will receive an event with the datatype of
00:41MouseEvent and I am actually going to give this a default value of null.
00:49So, let's set that MouseEvent = null.
00:51That way we can run playSong somewhere else if we want to.
00:55We don't have to rely on that MouseEvent.
00:57So, close out the parenthesis, :void, make sure the V is lower case and some curly braces.
01:05So, in here we will create a variable called soundFile, datatype it to a
01:10String, and we will set it equal to the name of the audio file that we are going to load.
01:17Now, my file is called 01 Eyes Wide.mp3.
01:26So, I have that file there, and now let's set sound equal to a new instance of
01:32the sound class using that new constructor, and then I will have the sound
01:38load the sound files.
01:39So, sound.Load and in the parenthesis here I am going to create a new URLRequest.
01:44And I will pass in soundFile.
01:51Now, of course soundFile could have been a URL request and we could have created
01:55the URL request right here.
01:56But I am just doing it this way, just a matter of personal preference, there's
02:00really no advantage to doing it this way.
02:02So, on the next line we will set, channel = sound.play.
02:10So, remember when you are working with audio, the channel is what controls all the sound.
02:17Even though this sound object has the play method, we put all of the control
02:22inside to that channel object.
02:23Because basically, all you can do with the sound is load it and play it.
02:27But with the channel, we can pause, we can resume, and we can even check the
02:32position of the sounds.
02:34So, all of that functionality is reserved to the sound channel class.
02:38And that's why we are setting the channel equal to the playing sound, or in
02:42other words sound.play.
02:44Because that method returns a sound channel instance that we can then control.
02:48And finally, inside of this method set, play_mc.visible = false.
02:54We don't want the play movie clip showing when the sound is playing, we want the
02:57pause movie clip showing.
02:59So we will set, pause_mc. visible = true, and that's it.
03:04So, save the file, and again we will just test it straight from this class.
03:09And we should be able to play this sound when we click the play button.
03:14(Music playing.)
03:20And looks like the sound is playing just fine.
03:22So, we now have successfully set up playing our external sound file.
03:28And by the way, if you load this sound and play it at the same time, then the
03:33sound will play before it's done loading.
03:36So, this is how you see sites, maybe like YouTube or other sites that have an
03:41external file playing before it's finished loading.
03:45You just tell it to play early, and as soon as there is enough data to play it,
03:51then the sound will just play.
03:53And will continue to load as the sound is playing.
Collapse this transcript
Pausing audio
00:00In this movie, we'll finish our Bare Bones audio player.
00:03By adding the functionality to pause and resume the sound.
00:08So let's scroll down to the constructor method.
00:13And right where we add the event listener, to play_mc, or to copy that line of
00:18code, and then paste it on the next line.
00:21In the pasted code, change play_mc to pause_mc and change playSong to, you
00:28guessed it, pauseSong.
00:30Right below the playSong method we'll define another public method called pauseSong.
00:37Just like playSong, you will receive an event with the data type of MouseEvent
00:42and we'll initialize to null, so that we can run this method whenever we want
00:46and we don't have to rely on a MouseEvent to trigger it.
00:49Inside of the method, we will set resumeTime equal to the position of the sound channel.
00:57Remember again, the Sound channel is the object that tracks the playback of the sound.
01:02So resumeTime=channel.position, remember that's going to be in milliseconds.
01:09Then we'll stop the sound, so channel.stop.
01:15By the way when you run channel.stop, the sound actually resets to 0.
01:20That's why you need to capture the sounds position in some sort of variable or property.
01:26So if you were to stop it, and then just play it again, it would reset from the beginning.
01:30Next, we'll set the visibility of play_mc to true, and pause to false.
01:42So pause_mc.visible=false.
01:44All right, once we stop the song, we want to show the play button, and hide the pause button.
01:50Now if you were to save the file, and test the movie, you would see that the
01:55sound would play again from the beginning, once you clicked play again, after
02:01you've clicked pause. So play.
02:03(Music Playing).
02:06Then pause, and then play again.
02:10And notice it starts from the beginning.
02:12(Music Playing).
02:19So what we will do is when we run this sound.play method in playSong, we will
02:25pass in the resumeTime to that method.
02:27So right in the parenthesis there, pass in resumeTime, capital T.
02:32So the Play method actually takes the parameter where you can tell it where to start.
02:37So we actually want to start in the middle of the song, wherever the person paused it.
02:41That's why we've captioned it, in the resumeTime property, and then we will
02:44resume from there when you click the play button again.
02:47So Save the file, and you may notice another glitch when you test it.
02:54So play (Music Playing), and then pause, and then play again.
03:00(Music Playing).
03:08Now one thing that could happen if you click and play and pause over and over
03:12and over again is that the original sound channel may not stop.
03:18You may just create a new sound channel every single time when you do that.
03:23So basically you have all these sounds layering on top of each other.
03:27And you don't want that to happen.
03:29And so here is how you prevent that.
03:31Go to the playSong method, and right below where we create that soundFile
03:35variable, use an if statement to see if channel exists already.
03:42So if channel exists, this basically just checks to see if it's undefined,
03:48then we'll stop it.
03:50So channel.stop, just to insure that we don't have any sounds playing over each
03:58other, because not only is that bad for memory, it's bad for people's ears.
04:03So let's save the file, and then just do a final test.
04:09So play and pause, and play and pause.
04:11(Music Playing).
04:22So it's resuming from the right time, and we don't have any sounds layering over each other.
04:28So our Bare Bones player is now complete.
04:32And just remember that whenever you want to resume a sound after you pause it,
04:38make sure to capture that resumeTime in a variable, and then pass that in when you play the song again.
Collapse this transcript
2. Controlling Sound Progress
Viewing the FLA file
00:00In this chapter we are going to add a Progress Bar and time tracking through our audio player.
00:06To start out, let's take a look at our FLA file.
00:09It's essentially the same file that we worked with in the previous chapter, with
00:14just a few additions.
00:15So on the stage here, I have my movie clip player_mc, and if I double-click it,
00:21I can enter its timeline.
00:22I'll zoom into the player, and then you could see that we have one movie clip
00:28called prog_mc, and then a text field called time_txt.
00:34Note that the time text field is a Dynamic Text field.
00:37I set the anti-aliasing to Bitmap text.
00:44And I'll make sure that the characters are embedded.
00:48Next, we'll double-click prog_mc to enter its timeline.
00:53Inside of prog_mc, there are two elements.
00:57The dragable element called drag_mc, and then the bar in the background, which
01:05is called the bar_mc.
01:07These are just simple bitmap graphics.
01:10Again, you can just use your own vector graphics if you like.
01:13And that's really all that there is to this FLA file.
01:16So it's the same one we worked within the last chapter, with the addition of
01:21this movie clip prog_mc, and this text field, time_txt.
Collapse this transcript
Creating the Progress class
00:00Now let's start looking at, how to use ActionScript to track the playback
00:04progress of our song.
00:07The first thing, I'm going to do is jump over to ProgressDisplay.as.
00:11This file is in the same package as the player class, so com.lynda.audio and
00:18should thus be into the exact same folder.
00:20Make sure you name it ProgressDisplay, capital P and capital D. I'm importing
00:27a bunch of classes here, so that all the display, events, text and geometry classes.
00:33I have my class definition here, note that it's not extending any class, and
00:37then I have my constructor method.
00:40Let's create some properties.
00:42So first, public property called resumeTime.
00:44Remember, we created a resumeTime property in the last chapter.
00:51This property is actually going to take the place of that property, so public
00:56var resumeTime:Number = 0.
01:00The other public property called drag and that's going to be a movie clip.
01:06Public property called bar.
01:08Also a movie clip, a public property called time_ txt.
01:13That's going to be the time text field.
01:15So it's a TextField.
01:16And then finally, a public property called player, datatype that too, Player
01:24capital P. That's going to refer to an instance of the audio player that we
01:29created in the previous chapter.
01:32In the constructor method, we'll accept some parameters.
01:34p will be a Player, d will be a movie clip, short for drag, b will be a movie
01:44clip that's short for bar, and finally t will be a TextField.
01:52And as you may have guessed, we're just capture all of these parameters in our properties.
01:57So player = p;
02:01drag = d; bar = b; and time_txt = t;
02:11and finally, we'll set drag.buttonMode = true.
02:14Remember that's going to show a hand cursor when you roll over it.
02:18Now, we'll define the skeletons of two public methods, one to initialize this
02:24object and one to disable it.
02:27So public function init(): void, so no return data.
02:34And then, I'm just going to copy and paste this method, and change init to disable.
02:39So we'll save the file, then we'll jump over to Player.as.
02:48The first thing we'll do in our Player class is delete that resumeTime property.
02:52After you delete resumeTime, scroll at the top of your code and create another
02:56public property, and call this one progDisplay, datatype it to ProgressDisplay.
03:08And scroll down to the constructor, and we'll initialize that property right
03:12below, where we set the visible property for pause_mc.
03:15So progDisplay = new ProgressDisplay, capital D capital P, and in the
03:25parenthesis we're going to pass in this- that's the player- and prog_mc.drag_mc,
03:37prog_mc.bar_mc and then finally, time_txt.
03:44Remember that drag_mc and bar_mc are both in that movie clip prog_mc.
03:49Now we're going to through, and find out those references to resumeTime and
03:53change it to progDisplay.resumetime.
04:00So in the playSong method, we'll change channel = sound.play(resumeTime) to
04:04channel = sound.play(progDisplay.resumeTime).
04:09And then, we'll add progDisplay and a dot right before resumeTime in pauseSong.
04:17And last, we'll initialize progDisplay in playSong and disable it in pauseSong.
04:23I'm going to initialize it, right above play_mc.visible = false in playSong.
04:28So progDisplay.init().
04:34And then in pauseSong, right below progDisplay.resumeTime,
04:38progDisplay.disable(). That's it.
04:47Save the file and if you test the movie, you should get the same functionality
04:51that you had before.
04:52You should be able to play and pause, and it should work just like you'd expected to.
04:57So test the movie.
04:58Click Play to play, and Pause to pause.
05:03(Music Playing)
05:05And then Play again to resume.
05:07(Music Playing)
05:11So now we have the progDisplay object controlling the progress of the song, the
05:16class is setup, and working properly.
Collapse this transcript
Showing progress in a text field
00:00In this movie, we will look at showing the progress of the playing sound.
00:04Both in the progress bar and in the text field.
00:07Scroll down to the init method.
00:10In the init method we are going to add an event listener to the player, so type
00:14player.addEventListener and for the event listener it will be Event.ENTER_FRAME,
00:22make sure that's all caps.
00:23And we will run a method called showPlayProgress.
00:26Play should have a capital P as well as progress.
00:35Just copy this code and then paste it inside of the disable method and just
00:39change addEventListener to removeEventListener.
00:43Below disable, define a private method called showPlayProgress.
00:52Make sure to make it receive an event with a datatype of Event, now return data
00:57and write some curly braces.
01:00The first thing you want to do is create an if statement.
01:02So, create the skeleton of an if statement, make some curly braces, and inside
01:07of the if statement we are going to see if player.channel exists or if there
01:12is a sound channel.
01:14And if player.sound.length != 0.
01:24So, we want to make sure that some of the sound at least is downloaded before
01:28we start tracking any progress because as the sound downloads, that length
01:33property increases.
01:35And we want to make sure that the sound channel exists as well.
01:38So, if those two conditions are true, then we will do the quotes and the curly braces here.
01:43So, the first thing we will do is create some variables, the first one will be
01:46called p and it will be equal to a number, this represent the sounds position.
01:52So, we will set that equal to player. channel.position, and we want in seconds,
01:58so we are just going to divide it by a thousand.
02:02And then on the next line, create a variable called and this will represent the
02:05length of the sound.
02:06It will be number as well.
02:09It will be equal to player.sound.length.
02:14So, if you want to know the total length of the sound, you need to get it
02:17through the sound object, not the sound channel.
02:20We are going to divide that by a thousand as well to get the value in seconds.
02:24Now, what we will do is set the position of the draggable part of the progress bar.
02:29So go down a few lines, and then type drag.x = (p/l), and so just a standard
02:40showing of a percentage of something.
02:42You just take the current value divided by the total value and that gives you the percent.
02:49And then you multiply it by the maximum value that you want.
02:54So, we are going to multiply it by the draggable object being all the way at the
02:58right and that's going to make a display just in the right spot based on the
03:04percentage that the song is played.
03:07So type (bar.width - drag.width) and that will align the draggable element with
03:15the right edge of the progress bar and that's it for that.
03:19So, save the file and then test the movie.
03:24You should be able to play this song and watch the progress bar move.
03:25(Music Playing)
03:26So we can pause this song and then resume and watch it resume at the right place.
03:33 (Music Playing)
03:38All right, now we will have the text field display of the current time.
03:48This is a little bit more complicated than adjusting the position of
03:52the draggable element.
03:53So, right below our p and l variables, we are going to get the position in minutes.
04:00And to do that we are going to make a variable called, pMin, set it as an
04:05integer and this will automatically truncate any floating point value.
04:11And to get that, we will just take p /60.
04:17That's pretty easy, right?
04:19And then to get the seconds, create a variable called pSec, set it to an integer.
04:24And instead of p / 60, we will do p % 60.
04:31Perfect tool for this.
04:33The percentage divides p by 60 and the percentage gives you the remainder that's left over.
04:41So, we are dividing that time in seconds by 60, we got the minutes.
04:45We will use the percent 60 and then we get whatever is left over,
04:49whatever seconds we have.
04:51Perfect tool for this situation.
04:53Go down a few more lines, create a variable called pStr, this is going to be
04:59our position string.
05:01So datatype it to a String, we are going to set it equal to a shorthand
05:05conditional statement here.
05:06So it's equal to pMin < 10, so if it's less than 10, we want it to start out with a zero.
05:14So we want it to say 01, 02, etcetera instead of just 1, 2.
05:18All right, after that you put a question mark and the question mark kind of means then.
05:26So, in there we are just going to put a 0 and then a colon. That's else.
05:31And then just put quote after that.
05:33So we are either going to start it out with 0 or nothing.
05:35Go to the next line and we are going to concatenate the value of our p
05:39string, so pStr += pMin.
05:44So, we start out by displaying the minutes and then we will add a colon on to
05:48it, so pStr += :, and then we will add on the second, so pStr +=, and then
06:00another shorthand conditional statement in there.
06:02We will see if, pSec < 10.
06:06Same thing we did for the minutes, if so, we are going to tack on a 0, if not we
06:11will tack on nothing.
06:13And then we will put the seconds in that string, so pStr += pSec. Not so bad, right.
06:20So just copy these lines of codes that we just wrote, all the way from pMin
06:24down to pStr += pSec.
06:27So, copy that and then we will paste it and basically follow the same
06:30formula for the length.
06:33So in the pasted code, change all the ps to ls.
06:37This is almost too easy, isn't it?
06:48All right, so just change all of those ps to ls and once you have done that,
06:55just double check, but make sure you didn't miss any.
06:58So basically, we are calculating the length text value in the exact same way we
07:04calculated the position value.
07:06So that's not too bad.
07:08And then right below that we will set the time text field to display the time.
07:12So time time_txt.text = pStr + "/" + lStr.
07:23So position forward slash length. That's it.
07:29Save the file, test the movie, and you should be able to click the play button
07:34and see the progress bar move and the time update in that text field.
07:37(Music Playing)
07:46And that looks just right.
07:47So, I paused it, and I will resume it just to make sure it's still correct.
07:53(Music Playing)
07:55Nice.
07:57So that it's working successfully.
07:59So, the main thing that you have learned in here that was probably new was how
08:02to use this percentage operator.
08:04Remember that you can get the remainder of something that you divide, so we
08:09divide l by 60 and we get the left over here and that's really useful for calculating seconds.
Collapse this transcript
Controlling progress
00:00Now that we've added the functionality to display the playback progress, we'll
00:05look at how to control the playback progress by clicking and dragging the
00:09dragable element on the progress bar.
00:12Scroll down to the init method, right below where we add the event listener to
00:16the player, add an event listener to drag.
00:21So, drag.addEventListener(MouseEvent. MOUSE_DOWN, run a method called dragProg.
00:30Copy and paste that line of code, enter the disable method right below where you
00:35removed your event listener from the player.
00:37Change addEventListener and the pasted code to removeEventListener.
00:41Right below the disable method, create a new private method called dragProg.
00:46It will receive an event with the datatype of MouseEvent.
00:59In the method, first thing we'll do is set the resume time.
01:01So, resumeTime = player.channel.position.
01:10We're basically doing here is capturing the resumeTime and pausing the song.
01:16So, on the next line, we'll actually pause the song, so player.pauseSong.
01:20Now, we'll start dragging the handle of the progress bar, so
01:26drag.startDrag(false, so we don't want to lock the center that way.
01:34That way the registration point of the dragable element, the top left of it
01:39won't lock to the center of your mouse, you don't want that to happen.
01:41So, false, and then we define the balance in the form of a rectangle.
01:45So, we'll actually create that rectangle right here.
01:47So, new Rectangle, and make sure to close up the parentheses for both the
01:53rectangle and for the startDrag method.
01:57And in the Rectangle constructor will pass in 0 for the X, 0 for the Y position.
02:03For the width we'll pass in bar.width - drag.width.
02:09That's the maximum X position we can drag a handle here, and then for
02:15height, we'll put in 0.
02:18So then I'll start dragging.
02:19Then we want to remove the event listener from drag, so we'll copy that
02:25drag.removeEventListener line of code from disable, paste it right below startDrag.
02:31Stop listening for that.
02:34Then we'll add an event listener to stage listening for mouse up.
02:37Remember you don't want to listen for mouse up on drag, in case the person
02:40moves their mouse up or down, then they will be off of that drag movie clip and it won't register.
02:47So, you want to add it to the stage so wherever they release their mouse, it
02:51will register and stop dragging that element.
02:54So, player.stage.addEventListener, then it's going to be MouseEvent.MOUSE_UP,
03:04make sure that's all caps.
03:07And we'll run a method called stopDragging.
03:11And now we'll define the private method stopDragging right below dragProg.
03:16So, private function stopDragging, receive an event with a datatype of MouseEvent.
03:21No return data, so :void.
03:29And in stopDragging we will set the resumeTime.
03:35The resumeTime is going to be based on the position of the handle.
03:39So, what we're going to do is put some parentheses in to find out the percentage
03:46position of the dragable object relative to the full dragable area.
03:54So, we just take its position, we divide it by the total dragable area and then
03:58we get its percentage position.
04:00And then we multiply that by the total length of the sound.
04:04Remember this is common math, you take the percentage, then you multiply by the
04:08maximum value and that gives you the value that you want.
04:11So, in the parentheses type drag.x, so that's the position.
04:17We're going to divide that by another value in parentheses, so I have two sets
04:23of parentheses here, and divide that by the maximum position for the drag.
04:27So, it's going to be bar.width - drag.width.
04:31So, that's the maximum X position.
04:33We're going to take that a whole value in both parentheses and we're going to
04:38multiply that by player.sound.length.
04:44So, to get the resumeTime we take the percentage position of the dragable
04:48element and we multiply that by the total sound length, and that's how you get
04:53where the sound should resume.
04:55Next, we'll play the song, so player.playSong and then drag.stopDrag.
05:02Then we'll add the event listener to be able to drag it again, so I'm just going
05:09to copy and paste that line since we already wrote in the init method,
05:13player.addEventListener.
05:14That line right there.
05:16Paste it at the bottom of stopDragging, and then we'll remove that event
05:20listener from the stage listening for MOUSE_UP.
05:24So, just copy that line of code from dragProg at the bottom and paste it at the
05:29bottom of stopDragging, change addEventListener to removeEventListener in the
05:34pasted code, and that's it.
05:37So, save the file and you should be able to test the movie and play the song.
05:43Once it's playing you should be able to click and drag that little handle to
05:47change the position of the song.
05:48(Music Playing)
05:57Looks like it's working just like it should.
06:00So, now we've successfully set up dragable functionality, so we can control the
06:05playback of the song.
06:06Now remember, the recipe for figuring out where the resumeTime should be is you
06:12take that percentage of where the dragable element is by dividing its current
06:18position by its maximum position, and multiplying that percentage value by the
06:24total length of the sound.
Collapse this transcript
3. Controlling Volume
Viewing the FLA file
00:00In this chapter, we will add a volume slider to our MP3 player and as usual, we
00:06will start out looking at our FLA file.
00:09So when you have your FLA file open, double click the player on the stage
00:13to enter its timeline.
00:15Inside of the player, I am going to zoom in, using the Zoom tool, right on
00:20that volume slider.
00:21So let's go to the volume slider and you will notice that it's a movie clip with
00:26an instance name of volume_mc.
00:29The movie clip is an instance of a movie clip called VolumeControl.
00:32So, if I double click that, I can enter its timeline.
00:38Notice that big, red block right there.
00:41That's actually the mask, so we are going to use that as a mask for the
00:45slider knows it's not set as a mask on the timeline but we will set it as a
00:49mask in ActionScript.
00:52For the record, that's always the best policy for items that you are going to
00:56animate using ActionScript, like we are going to do with the volume slider.
01:00So you can see it's just a movie clip that I called it mask_mc.
01:04There is really nothing special to it.
01:06You enter its timeline, you will see that it's just a shape.
01:09So I have that and there is this slider that's called slider_mc as an instance
01:16of the volume slider movie clip.
01:19If you double click it, you can enter its timeline and you see that there is
01:23not too much to it.
01:24There is a movie clip called drag_mc.
01:25It's just a bitmap and then there is the bar, which is called bar_mc, another
01:33bitmap, pretty straightforward and then the background is just a shape, just a black rectangle.
01:40Back to VolumeControl, and then if I hide the slider, you can see that there is
01:45the icon movie clip.
01:46That's a little sound icon and there is the background, which you can't really
01:50see unless you select it.
01:52It's just a rectangular background for the sound icon so that you get a little
01:56bit more hit area and that's it.
02:01So that's to look at our FLA file.
02:03For those of you, who don't have the exercise files, make sure to go through
02:07this movie very carefully, setting up your files in exactly the same way.
02:11Once your files will set up, you are ready to start writing the code for our volume slider.
Collapse this transcript
Creating the VolumeSlider class
00:00Now we will look at initializing the VolumeSlider class by adding some basic
00:04properties and writing some code in the constructor method.
00:08So, if you don't have access to the exercise files, make sure you declare the
00:11package com.lynda.audio and save the VolumeSlider file in that same folder.
00:18That would be the audio folder.
00:21Also make sure that you call it VolumeSlider with a capital V, capital S, same
00:26thing for the class name and the constructor method.
00:29Let's look at our import statements, importing flash.display.*, flash.events.*,
00:36flash.geom.*, flash.media.*, those are the sound classes and then gs.*.
00:43Now, if you have watched a lot of my training for Flash CS4, I have talked
00:48about TweenLite that's an ActionScript twining engine that an independent developer made.
00:56I use that for all of my ActionScript animation because it's very easy to use.
01:01So if you don't have that code and you are not familiar with it, I recommend
01:05going to tweenlite.com and then just download the TweenLite engine.
01:11When you download TweenLite, you will find a folder called gs.
01:15Take that gs folder and drop it into the same folder that you are using for the
01:19FLA file in this exercise.
01:22So, your file should look just like mine.
01:29So in your main folder, you will have the player, the song that you are going to
01:34load, the com folder and the gs folder.
01:37All right, let's declare some properties.
01:41So I will create a public property called vol.
01:44It's going to represent the main volume movie clip because we are not going to
01:49extend the MovieClip class or connect to this class to the VolumeSlider.
01:55We are actually going to just use it in the player class and pass all these
02:00values in as properties.
02:02So, I will create another public property called volDrag.
02:05This will be the dragable element.
02:07So, that's going to be a movie clip.
02:09Another public property called volBar.
02:12That's the bar in the background.
02:15It's going to be a movie clip as well.
02:16We are going to save the bar's X position.
02:19So, create a property called volBarX.
02:22That will be a number and then finally, create one more public property called player.
02:28This will represent the player that we are using which in this case is going to
02:32be Player.as or player class.
02:34It's going to be an instance of the player class.
02:36That way we can retain a reference to the player inside of this class.
02:42So, in the constructor method, we are going to take two parameters.
02:45p, that's going to be the player, and then v, which is going to be MovieClip.
02:51That will be the VolumeController movie clip from our FLA.
02:55So, we will just initialize it here. So player = p;
03:00vol = v;
03:03vol.slider_mc.mask.
03:05So we are setting the mask right here equal to vol.mask_mc.
03:13Set volDrag = vol.slider_mc.drag_mc.
03:21Set volBar = vol.slider_mc.bar_mc.
03:31Set volBarX = volBar.X and we will finally set the button mode of vol equal to true.
03:42So vol.buttonMode = true and remember that buttonMode just makes it so when
03:47you roll over a movie clip, it shows the hand cursor instead of just the regular pointer.
03:52So, we are just about ready to test.
03:54So save this file and then we are going to need to jump over to Player.as and
03:59adjust the code there.
04:02So, in my properties area, I am going to create a new public property.
04:06So, right below progDisplay, we will create another property called volSlider.
04:15Datatype it to a VolumeSlider and then we will initialize it in our
04:22constructor method.
04:23We will do that right below where we initialize progDisplay.
04:26So right below that volSlider = new VolumeSlider and inside of the parenthesis,
04:39passing this with reference to this player and volume_mc that's the reference to
04:48the VolumeControl movie clip and that's it.
04:51So save the file and we will test it right from here, just to make sure your
04:56target is player.fla.
04:58You can test the movie and you really shouldn't see anything special.
05:02Everything should work as it did before.
05:04(Music Playing)
05:06And then you should see that the red area has become the mask and has hit in the volume slider.
05:15So we just have the volume slider and when you roll over the volume movie clip,
05:19you should see the hand cursor.
05:20It looks like everything is working properly.
05:23So now our basic VolumeSlider class is set up and ready to work with.
Collapse this transcript
Animating the slider
00:00Now, we'll add the functionality so that when you roll over the sound icon in
00:04the Music Player, the Volume slider will slide up and that when you roll out,
00:09the Volume slider will slide down.
00:11We'll start out in player.as.
00:14In that file, find the playSong method.
00:17In the playSong method, right above progDisplay.init we'll initialize the Volume slider.
00:23So type volSlider.init and some parenthesis and a semicolon and we'll define the
00:32Init method right now.
00:33So save the file and jump over to VolumeSlider.as.
00:38Right below the constructor method, go down a few lines and define a public
00:42method called init.
00:44No parameters, no return data.
00:48In the Init method, we'll add an event listener to vol, so when you roll over
00:52it, we'll run a method called volOver.
00:55So vol.addEventListener, event is going to be MouseEvent.ROLL_OVER, and the
01:02method will be volOver.
01:05Right below the Init method, we'll define a private method called volOver, or
01:12receive an event with a data type of MouseEvent, no return data and in volOver,
01:19we are going to use TweenLite to animate the Volume slider.
01:24The syntax is TweenLite. to, and some parentheses.
01:31Now, if you are unfamiliar with the TweenLite engine, you'll see here that it's
01:35actually pretty easy to use and to get used to it.
01:38The TweenLite.to method takes an object's current properties and then animates
01:43them to whatever values you pass in.
01:46So the first parameter is going to be the object that you want to tween.
01:50That's going to be vol.slider_mc.
01:55The second parameter is the duration of the tween.
01:58So we want the tween to be 0.5 seconds, so just type in .5 and the third
02:02parameter is an object.
02:03So I am going to create a shorthand object here.
02:06Here you can pass in the Tween properties.
02:08So if you want to animate the Y position, you just pass in where you want the
02:13object to end up on the Y-axis.
02:17You do that by just specifying a Y property inside of the object.
02:20So Y:-vol.slider_mc.height.
02:29So it's going to end up at the vol slider's negative height, which means the
02:33slider is going to be at the top of the volume movie clip.
02:38So again, that Y property is just saying where we want the Y property to end up
02:42at the end of the tween.
02:44The next property we'll passed in is called onUpdate.
02:48This allows you to identify a method that will run every time the tween updates.
02:53So onUpdate:volTweenUpdate and we'll add an event listener to vol, listening for
03:04MouseEvent.ROLL_OUT, run a method called volOut.
03:11So I am just going to copy and paste volOver and change it to volOut.
03:21Change the Y position from - vol.slider_mc.height to 0.
03:27That will animate the slider's Y position to 0 when you roll out.
03:32Then just delete that last line of code.
03:33Now, all we have to do is define the volTweenUpdate method that we specified
03:39in the volOver method.
03:40So create another private method, call it volTweenUpdate, no parameters, no
03:50return data and in here, all we are going to do is just reset the mask for the slider.
03:58Remember that when you animate an element with ActionScript or move it at all,
04:03if that element is masked, it's going to be unmasked as soon as you move it.
04:07So you need to reset that mask every time you move the object.
04:11So I am just going to copy that code where I set the mask.
04:14That's inside the constructor method.
04:16So it's with vol.slider_mc.mask, and I'll paste it right inside of
04:22volTweenUpdate and that's all we have to do.
04:25So save this file and you should be able to test it and because the volume
04:32doesn't initialize until a sound is playing, you have to play the sound first.
04:36(Music Playing).
04:41And you can even pause it and it will still work.
04:42So I am going to pause it and I will roll over that movie clip and you will see
04:45the slider go up, roll out, and see the slider go down.
04:49All right, our Volume slider is successfully animating using TweenLite.
Collapse this transcript
Adding the slide effect
00:00Up to this point our volume slider itself doesn't have any real interactivity.
00:05In this movie, we'll add the interactivity so you can click and drag the
00:08volume slider up and down.
00:11Let's go to the constructor method in the VolumeSlider class.
00:15At the very bottom of the constructor method, add an event listener to volDrag.
00:19So volDrag.addEventListener, and the event is going to be MouseEvent.MOUSE_DOWN.
00:27And we'll run a method called dragVol.
00:31We'll define dragVol right below init, so scroll down below init.
00:37Create a private method called dragVol.
00:40It will receive an event with the data type of MouseEvent, no return data.
00:48And instead of the method we'll type volDrag.startDrag, and for the first
00:54parameter we'll pass in false, remember that's lock center.
00:57It will lock the mouse to the registration point of the object, which we don't
01:00want to do in this case.
01:02The next parameter is a rectangle and that's the balance for the drag.
01:07So create a new rectangle right here in line, and for the rectangle make sure
01:14you have closed parenthesis for both rectangle and startDrag.
01:17We'll start out with rectangle's X position 0, the Y position is volBar.y, the
01:25width will be 0, and the height will be volBar.height - volDrag.height.
01:35That will bring that dragable part to the very bottom of the volBar.
01:40Next, we'll remove that rolloverEventListener.
01:44So vol.removeEventListener(MouseEvent. ROLL_OVER, make sure that's all caps, and
01:53the method is volOver.
01:56On the next line we'll add an event listener to the stage to listen for
01:59MouseEvent.MOUSE_Up.
02:00Remember that when you are dragging something, you always want to add the up
02:04listener to the stage not the object.
02:07That way you could be sure to capture any MOUSE_UP event.
02:10So player.stage.addEventListener.
02:16That's going to be MouseEvent.MOUSE_UP.
02:22Run a method called dropVolBar and we'll define that right now.
02:29So right below dragVol, create a private function called dropVolBar.
02:38It will receive an event with the datatype of MouseEvent, no return data.
02:47The first thing we'll do is stop dragging the volume bar, so volDrag.stopDrag,
02:54no parameters there.
02:56Remove the event listener from the stage.
02:58I am just going to copy that line of code and paste it,
03:01player.stage.addEventListener from dragVol, right below volDrag.stopDrag.
03:08And then I will just change addEventListener in the pasted code to
03:12removeEventListener.
03:14Then whenever you drop the volume bar, I want the volume slider to
03:19automatically slide down.
03:21So I am going to run volOut.
03:28Now I am going to have to modify the volOut method in my code on line 54.
03:32I am making this so I can run this method without requiring an event.
03:39To do that, I simply have to initialize the event parameter to null, so I will
03:43just set event:MouseEvent = null.
03:47That way we can run this method without needing an event and we just have to add
03:51one more line of code to complete this step.
03:54So scroll up and find the dragVol method.
04:00In the dragVol method we will remove the event listener from vol so we'd no
04:04longer listen for the MouseEvent.ROLL_OVER event.
04:07What do we want do is add that event listener again when you drop the volBar, so
04:12copy that line of code and paste it at the bottom of the dropVolBar method and
04:17change removeEventListener to addEventListener.
04:21So after you do that, save the file.
04:24So I will test the movie and everything should work just as you would expect.
04:28You should be able to play the song, move the slider, and then show and hide the
04:33slider at your will.
04:35(Music Playing)
04:45And looks like it's working great.
04:47So that completes that step and we have successfully added slide to our slider.
Collapse this transcript
Controlling volume
00:00In this movie, we'll complete our volume slider by actually making and control
00:04the volume of our sounds.
00:06So the first thing, I wanted you to do is scroll down in Player.as down to
00:11the playSong method.
00:13And right above volSlider.init, we'll call a method that we haven't defined yet,
00:17but we will define later in this movie, called volSlider.updateVolume, and of
00:26course that method is going to update the volume of the sound.
00:29Now the thing is every time we play this song, we want to run Update Volume to
00:34make sure that the volume is the same as it was for the last song.
00:39That's because every time we play a song, we're creating a new instance of the
00:42sound class, so we need to reset that volume every time.
00:46So, let's save this file, and then head on over to VolumeSlider.
00:51In VolumeSlider scroll down and find the dragVol method.
00:58At the bottom of this method, it's adding event listener to the player.
01:02This is going to be EnterFrame event.
01:03So player.addEventListener, events going to be event.ENTER_FRAME, and we run a
01:11method called updateVolume.
01:14And before we define updateVolume, I am just going to copy and paste this line
01:19of code at the bottom of the dropVolBar, and there I'll change addEventListener
01:26to removeEventListener.
01:27We don't want this EnterFrame event listener on forever, we want definitely
01:32remove the event listener when we are done, because that's going to use a lot of
01:35memory that we don't need to be using up. So, right below dropVolBar, I am going
01:40to define a public method called updateVolume.
01:43Remember that we are running this from the player class file so we'll need to
01:49make this method able to run without an event being triggered.
01:53So event:Event, I'll set it equal to null, so we can run it from the other class.
02:01Now return data, and here we'll create a variable called trans, I'll set it
02:07equal to SoundTransform object, and that object will be
02:12player.channel.soundTransform.
02:17And that's the object that holds the sound transform for the songs.
02:21We are going to hold it in that trans variable here, and then we'll manipulate
02:24it, and then reapply it to the sound object.
02:28So go to the next line and create a variable called volPercent, this is going to
02:33be a number, and what I am going to do is I am going to set it equal to
02:39volDrag.y - volBar.y, so this is it's positioned relative to the volBar, and we
02:51are going to divide that by a value of parenthesis and so in the parenthesis put
02:57volBar.height - volDrag.height.
03:04That's the maximum value that a volDrag can be down.
03:07So, we are seeing its position from top to bottom.
03:10So, the top value is going to be zero , and the bottom value is going to be 100.
03:14That's kind of exactly the opposite of what we want, so when we apply this
03:18transformation of the sound, we are going to need to work with it just a little bit.
03:22So go down to the next line, and I will say trans.Volume = and put a value in
03:27parenthesis here, make it negative, and we'll put, volPercent - 1.
03:30Let me show you my logic on that.
03:35So we have that 0 to 1, so 0 at that point, 1 at the bottom.
03:38We are actually wanted to be 1 at the top, 0 at the bottom, so we are reversing
03:43it when we set the volume.
03:44Here is how that works.
03:45You take that volPercent we subtract 1 from it.
03:48So, let's say it's 1.
03:51We subtract 1 at 0 and if it's 0, we subtract 1.
03:54That's a negative 1.
03:54So that gives us the exact values that we want except for their negative.
03:58So we multiply that by negative 1 here.
04:01So that changes that negative value to a positive value and gets it in that
04:06correct range that we are looking for.
04:07And now we use some if statements to make sure that the volume doesn't go
04:11above 1 or below 0.
04:13So we'll check to see if trans.volume is greater than 1.
04:17We just set it equal to 1.
04:20So trans.volume = 1, and then below that, if statement, create an Else if
04:24statement and check to see if trans. volume is less than zero , and if so we'll
04:31set trans.volume equal to zero.
04:34I recommend to always doing this when you are working with sounds, because if
04:37the volume is greater than 1 or less than 0, it's going to sound distorted.
04:42So, you always want to make sure that it's staying between 0 and 1.
04:47And finally, we just have to reapply that transformation to our sound, and to do
04:51that type player.channel.soundTransform = trans.
05:00So remember that after you adjust the volume of a sound, you need to
05:03reapply that adjusted volume to the soundTransform property of your sound channel object.
05:10So once you do that, you are ready to save the file, and then test the movie to
05:14see the volume control in action.
05:16So I am going to play this song, and then I am going to control the volume.
05:21(Music Playing)
05:28So, you can see that it works just as you'd expect.
05:31So now we have complete control with our volume slider, and that completes our volume slider.
05:38Now I want you to remember that whenever you are working with sound, make sure
05:42that you adjust the volume between 0 and 1.
05:45Make sure it never goes below 0, or above 1.
05:49Finally, once you make an adjustment to the volume, you'll need to reapply it to
05:54the soundTransform property of your sound channel object.
Collapse this transcript
4. Working with an XML Playlist
Viewing the working files
00:00In this chapter, we are going to apply an XML playlist to our MP3 player.
00:06We'll start out by looking at the files we'll be working with.
00:09First we'll look at data.xml, this XML file has all of the XML data we'll be
00:15working with, throughout this chapter.
00:18Let's take a look at how it's structured.
00:19The outer root node is called Album.
00:23So, you can see the opening tag there where I have that highlighted and then the
00:27closing tag at the bottom.
00:29Then there is repeating element called Song.
00:32So each song has its own element.
00:37Inside of each Song, there is an element called File, and an element called Name.
00:43The File element contains the file name of that Song.
00:46For example, we have 01 Eyes Wide.mp3 here and the name corresponds to the name
00:55of the song, which is just Eyes Wide.
00:59So, that goes for each song in this XML file.
01:03So, if you don't have the exercise files, create an XML file in a Text Editor.
01:09Do not use Microsoft Word to do this.
01:13Use Text Editor on the Mac, or Notepad on the PC, if you are not sure which
01:19Text Editor to use.
01:21The reason why I tell people not to use Microsoft Word is because Microsoft
01:24Word puts a bunch of extra content inside of the text files, what you want is a plain text file.
01:32So, whether you're using TextEdit, Notepad or some other application, make sure
01:35you're not in Rich Text mode but that you are in Plain Text mode.
01:39So, when you have your file, just save it as data.XML and save it in the same
01:43folder as your FLA file.
01:45And speaking of FLA files, let's take a look at the one we have here.
01:49So here I am in player.fla and on the stage I have my player and there are
01:55some new elements in it.
01:56So I am going to double-click the movie clip to enter its Timeline.
01:59I added two buttons a Back Button or a Forward Button.
02:04The Back Button is called prev_mc, just a simple graphic, and the same thing for the next_mc.
02:12It's a simple graphic called next_mc.
02:14If you want me to prove it, I can double-click it to enter its timeline, and you
02:19can see it is just a simple grouped object, and if you were to ungroup it, you'd
02:24see that there is two bitmap images.
02:26It's actually just a copy of the Play button. Very simple there.
02:30So, those buttons are new and then on the right side, we have info_btn.
02:36This is just a button that's going to show and hide info_mc and if you
02:42double-click info_mc, you can see there is a black shape in the background, and
02:47there is a text field in the foreground called info_txt.
02:53As with all text fields which you are using that are dynamic, if you want to
02:58have them fade-in or fade-out or rotate or anything, you have to embed the
03:02font in that text field.
03:03So, that's how our FLA file is setup.
03:08Once you have your XML file and FLA file setup, you're ready to start writing
03:12the code for this application.
03:14Once you've your file setup properly, you are ready to start writing the code to
03:19add XML data to your MP3 player.
Collapse this transcript
Creating the PlayerModel class
00:00When you are creating a complex application, like our MP3 player, it's good
00:05to keep data separate from interactivity and data and interactivity separate from design.
00:13One way to do that is by using something called the Model View Controller Design Pattern.
00:20In my title on Object Oriented Programming, I showed you how to use the Model
00:26View Controller Design Pattern.
00:28In this title we will use that pattern but I won't discuss it in as much detail.
00:34So, if you are hungry for more information on that, go to the Object Oriented Programming title.
00:40In the Model View Controller Pattern, the model holds data for an application.
00:46So, in our music player, we are going to have the player model class control the
00:52XML data for our application.
00:54So, let's create a few properties here.
00:56First, I will create a public property called currentIndex, data type it to an
01:05integer and set it equal to 0.
01:09Create another public property called totalItems.
01:14That will also be an integer.
01:16Another public property called Loader, data type it to URLLoader.
01:23Another public property called data, data type that to XML.
01:27Notice data is a reserved keyword in Flash.
01:31If you don't like using reserved keywords, feel free to use something else.
01:35I just like using Data because it's very intuitive for me when I am using this
01:39class in another application.
01:42I always think data is going to hold the XML data for my application.
01:47Again you can use whatever you want.
01:48It's not really important what you call it.
01:50I just prefer data and finally I am going to skip a few lines and then create a
01:56Public Static Constant called MODEL_CHANGE.
02:02We will use this with our event dispatching.
02:05This is going to be a String and I am going to set it equal
02:08to playerModelChanged.
02:15In the Constructor method, I will set it the loader equal to a new instance of
02:19the URLLoader class.
02:21Then I will add an event listener to the loader to listen for Event.Complete.
02:30Then I will trigger a method called dataLoaded.
02:33Now, I will define the dataLoaded method as a private method, just going to
02:42receive an event with a data type of Event, no return data, and inside
02:50dataLoaded, I am going to set data equal to a new instance in the XML class and
02:57then pass in loader.data.
03:01So, that will create an XML data out of the loader's data and I will
03:05set totalItems = data.*
03:12That gives you an XML list of all of the child nodes of the root node of our XML object.
03:20.length and some parenthesis because length is a method when you are
03:25working with an XML list.
03:28Then I am going to run a method called setCurrentIndex.
03:29We will define that in just a minute, I am going to pass in currentIndex.
03:38And finally I am going to dispatch the complete event. So dispatchEvent.
03:44That's why I have extended the EventDispatcher class for my player model, so I
03:49can dispatch events.
03:51And in the parenthesis, I will create a new event and inside of the parenthesis,
03:56I will type Event.COMPLETE.
03:58So, I am going to dispatch that complete event.
04:02Now, I will define setCurrentIndex.
04:04I will do that right below dataLoaded.
04:07This is going to be a public method.
04:09So type public function setCurrentIndex.
04:15A receiver parameter called index.
04:18That's going to be an integer, no return data.
04:22See here also the value of currentIndex, so currentIndex = Index, whatever is passed in.
04:31And then what we want to do is just make sure that if index value is too high,
04:36it will loop around.
04:37So, if somebody is like skipping tracks forward and there at the last track,
04:41and then go to skip to the next one, it will just loop around and go back to the first one.
04:46So, if(currentIndex >= totalItems) currentIndex = 0;
05:00else if (currentIndex < 0) currentIndex = totalItems - 1;
05:13Remember we are subtracting 1 to offset that value because totalItems is going
05:17to start at 1 and the index values are going to start at 0.
05:22So, we need to offset that by subtracting 1.
05:24So, the highest value is 1 less than the total number of items.
05:30And then we will dispatch the change event because the current index has changed.
05:34So, dispatchEvent, new Event and in the parenthesis for newEvent, I am going to
05:43type PlayerModel.MODEL_CHANGE in all caps just like I typed it above.
05:51You could even copy and paste it if you would like. And there we go.
05:56So we have written a lot of code here.
05:59I just want to make sure that this class is running properly so, I am going to
06:02add a trace statement at the bottom here.
06:05So, we will trace player model running.
06:10We will save the file and then jump over to Player.as and create a public
06:18property called model.
06:21Data type it to a PlayerModel and in the constructor, we will initialize it.
06:29Model = new PlayerModel.
06:35Now, you should be able to save this file and test the movie and just see the
06:39PlayerModel class is running properly.
06:41So, we have the trace statement and looks like we are good.
06:46So, now we have set up our PlayerModel class and it has all the methods
06:52necessary to work with XML data.
Collapse this transcript
Loading XML data into the player
00:00In this movie, we will look at loading XML data into our music player.
00:04The first thing I am going to do is move over to PlayerModel.as and just
00:08delete that trace statement that we wrote in another movie.
00:11It is on line 19 in my code.
00:13So, I will save that and then go to Player.as.
00:19In the Player file, right below where I define the model and of constructor
00:24method, I am going to add an event listener to the model.
00:27And I will listen for Event.COMPLETE and when that event occurs, I will run a
00:35method called xmlLoaded.
00:41So, I am going to scroll down toward the bottom of my code, create a private
00:45method called xmlLoaded.
00:50Remember that it will receive an event with a data type of Event and inside of
00:55the method I am going to add an event listener to the model to listen for
01:01PlayerModel.MODEL_CHANGE and then run a method called modelChanged.
01:14Now, I will define modelChanged, so a private function, modelChanged and this
01:23is a reserved Flash keyword, but it doesn't apply to movie clip, so it is okay to use that here.
01:31Again if you don't want to use reserved keyword, feel free to use something else.
01:37So, I will listen an event with the data type of Event, void for no return data
01:42and in here we will set progDisplay.resumeTime equal to 0.
01:49So, every time the model changes we will reset the resume time and then we will
01:55run the playSong method.
02:00And then we will scroll up to playSong.
02:02Now, instead of the sound file being a direct string, we are going to get that
02:08data from the XML file.
02:11So, in playSong, I am going to change soundFile.
02:12I am going to set it to model.data.
02:16That's our XML object . song and then square brackets.
02:23This is going to be the index number of the song.
02:26We will have to remember song is a repeating element.
02:28So, an XML repeating element is called an XML list.
02:33When you are working with an XML list in ActionScript, you can access the
02:37individual entices of that list using array-access notation, which is why I am
02:42using square brackets here.
02:44So, inside of the square brackets, I am going to type model.currentIndex.file.
02:52Now, because we are relying on the XML data when we play the song, when we
02:57add the event listeners to the play and pause buttons, we should do that
03:00after the XML data is loaded.
03:02So, I am going to scroll up and I am going to find play_mc.addEventListener and
03:07pause_mc.addEventListener in the constructor method and I am going to cut them
03:13and paste those two lines at the bottom of the xmlLoaded method that I created
03:18earlier in this movie.
03:19So, once the XML is loaded, then you can push the Play and Pause buttons to work with song.
03:25Last thing we are going to do to get this to work is we will load the XML
03:29data into the model.
03:34Right below where we add the event listener to the model, we will have the
03:36model load in XML file.
03:38So, model.load and in the parenthesis we will pass in a new URLRequest and the
03:47request will be for data.xml.
03:51Save the file and jump over to PlayerModel.
03:59In here, we will define the load method that we just referenced.
04:05So, I will create a public method called load.
04:07Again this is a reserved keyword, but it is very intuitive for me to use
04:11a method called load.
04:12So, I am using it anyway and we will receive a parameter called req, which is a
04:17URLRequest, no return data and this will make the loader load that request.
04:27Now, the XML file will load, the data loaded method will trigger in here,
04:33triggering the complete event, setting the current index and everything
04:39should work properly.
04:40So, let's save the file and you should be able to test the movie and not have
04:44any errors and then click the Play button and the song should play.
04:46(Music Playing)
04:54All right, so now we know that it is loading from the XML file.
04:59And the last thing to do with our XML data is display the name of the song in
05:05the info text field.
05:06So, I am going to go Player.as and near the top of the constructor right above
05:15where we set the model, I am going to set info_mc.visible equal to false.
05:24Then once the XML is loaded, I am going to add an event listener to
05:30Info_btn.addEventListener.
05:34Event is going to be MouseEvent.ROLL_OVER.
05:38I will call this showInfo and then I am going to copy and paste that line of
05:48code, change the event to ROLL_OUT and showInfo to hideInfo and Right below
05:57xmlLoaded, I will define showInfo and hideInfo as private methods.
06:05So, showInfo will receive an event with the data type of MouseEvent and inside
06:14of showInfo I will set info_mc. visible property equal to true.
06:22Then I will set that text field.
06:23So, info_mc.info_txt.text = model.data.song some brackets,
06:35model.currentindex inside of the brackets and then after the closed bracket,
06:41I am going to type .name.
06:43That's going to be the name of the song.
06:45So, it is going to go on that text field.
06:47I am going to copy and paste this method, change the name of the method to
06:53hideInfo, change visible equal to false and then delete that second line
07:00inside of the method.
07:02So, let's save the file and we should see that song name appearing in that info text field.
07:08Test the movie, play the song.
07:09(Music Playing)
07:09I am going to pause this song and then roll over the info box and then it shows
07:19the name of the song.
07:20So, now our player is connected to XML data instead of having to update the
07:28songs inside of our ActionScript, we can do everything through the XML file
07:33making a much more efficient application.
Collapse this transcript
Creating the PlayerController class
00:00In this movie, we'll look at making the PlayerController class.
00:04The PlayerController class will manipulate the XML data in the player model.
00:09This will allow us to add functionality like forward and back buttons to go
00:14through tracks in the playlist.
00:16if you don't have the exercise files, make sure to create PlayerController.as in
00:21the same folder as your other classes.
00:23That's the com.lynda.audio package.
00:26Make sure that you capitalize the P in Player and the C in Controller.
00:31The first thing I am going to do is create a public property called model.
00:35I am going to data type that to a PlayerModel.
00:39Notice that I don't need to import the PlayerModel class, because it's in the
00:42same package as PlayerController.
00:44In the constructor method, I am going to receive one parameter called m. That's
00:49going to be a PlayerModel.
00:52And then in the constructor, I am just going to set model = m;.
00:55Now I am going to define some public methods, one called addNextButton.
01:00It's going to receive a property called btn that's a DisplayObject.
01:14In there, I am going to type btn.addEventListener and the event is going to be
01:19MouseEvent.CLICK and we'll run a method called nextItem.
01:24And I am just going to copy and paste this method.
01:30Change addNextButton to addPrevButton and the same thing for the nextItem
01:37method, we'll just change it to prevItem.
01:41So now that find some private methods called nextItem and prevItem.
01:52So nextItem is going to receive an event with the datatype of MouseEvent.
01:54Now we return data.
01:57And in here, we'll run model. setCurrentIndex, and in the parenthesis, we will
02:04just pass in model.currentIndex + 1.
02:11Copy and paste this method.
02:14In the pasted code, change nextItem to prevItem, and change the plus to a minus.
02:22So basically this class simply takes a button that you pass in through
02:26addNextButton or addPrevButton, and adds the event listener to it.
02:31Whenever you click that button, it just manipulates the model forward one or back one.
02:36Since the model is connected to the player, when the model changes, the model
02:42change event will occur and change the player's track.
02:47So let's save the file and then open up Player.as.
02:51So in Player.as, I am going to create a new public property called controller,
02:59datatype it to PlayerController, and then I'll initialize it right after I
03:04initialize the model in the constructor method.
03:08So controller = new PlayerController, pass in the model, and then I'll set the
03:19controller's next button and previous button.
03:22So controller. addNextButton passing in next_mc and
03:31controller.addPrevButton, passing in prev_mc.
03:40And then I want to see the hand cursor when I roll over the next and previous button.
03:43So next_mc.buttonMode = true;
03:49and prev_mc.buttonMode = true;. That's it.
03:54So save the file and then test the movie, and you'll have to play the song first
04:01for this to work, but you should be able to change tracks when you click the
04:04next and the previous buttons.
04:06(Music Playing).
04:12And notice that you can change the tracks and you can still view the MP3
04:16information, from the XML file when you roll over the Info button.
04:19(Music Playing).
04:21So that completes adding the XML functionality to our player.
04:34So instead of making changes like song information, playlist information, all of
04:41that using ActionScript, you can make all of the changes to the XML file and
04:46everything in the Flash application will automatically update.
Collapse this transcript
5. Accessing Sound Wave Data
Viewing the working files
00:00In this chapter we are going to look at how to display sound wave data in
00:04a Flash application.
00:05We'll start by looking at the file we are going to be working with.
00:08First we'll look at player.fla.
00:11As with all of the files we've have been working in this title, the player is on
00:15the main timeline and called player_mc.
00:18If I double-click the player, I can enter its timeline.
00:22Really there is nothing that I have added to this file for this chapter.
00:26I have just left an empty space on the right side and that's where the sound
00:30waves are going to go.
00:31All of the sound waves are going to be generated dynamically using ActionScript
00:36with the drawing API.
00:38API stands for Application Programming Interface.
00:42It's basically a group of methods that you can use to draw shapes
00:46using ActionScript.
00:47That's it for player.fla.
00:49Let's go over to SoundWaveData.as.
00:53Now notice this file is in com.lynda.audio package.
00:56So if you don't have the Exercise files, go ahead and create this file now. SoundWaveData.
01:00Make sure to name everything properly.
01:06Import these classes all the display, events, media and utils classes.
01:12Create some properties, a public property called height.
01:16This will represent the height of the sound waves.
01:19That's going be 12.
01:19Width, which will represent the width of the sound waves, which will be 16.
01:24Again, I am using reserved keywords, because it's intuitive for me to do.
01:28If you don't want to use these reserve keywords, then feel free to use something else.
01:33Just make sure to substitute later on.
01:36So then we have colorL, this is the color for the left channel line.
01:41I chose white there.
01:43This is the color for the right channel line.
01:46I also chose white.
01:47So you can feel free to put in any hexadecimal color you want right here.
01:50If you want to mix it up a little bit.
01:52I have a public property called Sprite, public property called Player that is a
01:56instance of the Player class, and then a private property called allBytes,
02:02which is a ByteArray.
02:03We'll talk about byte arrays in just a minute.
02:07So, here is a constructor method for SoundWaveData.
02:09It receives two parameters.
02:12One is called p, which is the Player, and then s, which is the Sprite.
02:15And the Sprite is going to be the Sprite that draws all the sound wave data.
02:20So that's going to be created in the player, and then passed into
02:23this constructor method.
02:24So I am just setting Player and Sprite equal to p and s respectively, then I
02:28create a new instance of a ByteArray.
02:30Now basically a ByteArray is just like the name implies, an array of bytes.
02:36So when you are working with sound wave data, all of the byte information for
02:40the sound is transferred into this byte array.
02:44Then you can display that data visually by extracting the data from the byte array.
02:49Now we'll looking in doing that in another movie.
02:51But that's just so you understand what a byte array is.
02:53Then I have few methods here, init and disable.
03:00And init, as an event listener to listen for the ENTER_FRAME event, runs
03:04showSoundWaves and disable does guess what, removes that same event listener.
03:09Remember that whenever you are working with an ENTER_FRAME event, you want to
03:12make sure to remove the event listener to optimize your application.
03:15So we haven't defined showSoundWaves.
03:17Yes we will do that in another movie.
03:18Now let's jump over to Player.as.
03:21In this file I have added some code to create a new Sprite, and to create an
03:27instance of the SoundWaveData class.
03:31In the constructor I create that Sprite add it to the stage, put it at X of 277 and a Y of 2.
03:38These aren't just random numbers.
03:39I actually plot it out visually in the FLA file, and then I wrote down the
03:44coordinates, and then put them here.
03:47So if you don't have the Exercise Files, you have to find out where you want
03:50the sound waves to be, write down those coordinates and then plug them in right here.
03:55Then I've created the new instance of SoundWaveData passing in this the Player,
03:58and sprite, and if you scroll down at the bottom of playSong, I initialize the
04:05SoundWaveData object, at the end of pauseSong, I disable it.
04:09So once you have your file setup, and ready to go.
04:12You are ready to start writing the code to display sound wave data through the Flash Player.
Collapse this transcript
Working with sound wave data
00:00Now, we'll look at taking sound wave data and displaying it visually using
00:05Flash's Drawing API.
00:08In my sound wave data class file, we're going to scroll down to show sound waves.
00:14The fist thing I'm going to do here is create a variable called lineY.
00:17This is going to represent the Y position of the lines that we're going to draw
00:24for the left and right sound channels.
00:26So, I'm going to set it as a number equal to 0.
00:29I'm going to go down a few lines, and then I'm going to use the method SoundMixer.
00:37SoundMixer is in charge of general sounds for all of the Flash applications.
00:43So, this controls all sounds .computeSpectrum.
00:48This method takes a Byte Array, and then puts the sound wave data inside of
00:53it, so that you can output it visually if you want to, or do whatever you want
00:58with that information.
00:59If you have more than one sound channel object in your application, this will
01:04apply globally to all the sound channels in your applications.
01:07So, just keep that in mind as your using this.
01:10So, now the first property that we've put in is the Output Array, and that's
01:16going to be our Byte Array.
01:17So, just pass in the Byte Array, which is going to be allBytes.
01:22The next property is called FFT Mode.
01:25Now, what this does is the default value is false, so I'm going to leave it at
01:30false, and just close up the parentheses.
01:32This displays the sound wave data as a waveform.
01:37Each byte will have a value between -1 and +1.
01:42If you put a value of true, then the bytes will represent sound frequency and
01:49give you values between 0 and about 1.4.
01:54For this exercise, I'm just going to set it false.
01:56You can definitely experiment setting it to true, and see what you get.
02:00So, I'm going to go down a few lines, and then I'm going to clear the graphics
02:05that are currently inside the sprite.
02:06So, sprite.grapics.clear.
02:09You can use the Drawing API by accessing any sprite's graphics property.
02:14So, that goes for removing clips in the main time, and they'll have the graphics property.
02:19So, we're clearing it to erase any graphics that already exist.
02:24Then I'm going to set the line styles.
02:26So, sprite.graphics.lineStyle, and first we've to put in the thickness of the
02:33stoke, which I'm going to put 1, for the color I'm going to use colorL.
02:38That's the color for the left channel.
02:40Then for alpha the default value is 1, so I'm just going to close in
02:43the parentheses there.
02:44Let's go to the next line, and then I'm going to use the moveTo method to define
02:49where I'm going to start drawing a line.
02:51So, sprite.graphics. moveTo and then I'll pass in 0.
02:56
02:57So, it'll be an X of 0 and then the Y, which is just going to height.
03:04So, we'll start drawing from there.
03:06Next, I'm going to create a for loop, to that i variable, and as i is less
03:14than width, do i++.
03:17Then I'm going to use a loop along with our Byte Array to display the
03:24left channel visually.
03:26So, type for var i:uint = 0; i<width; i++.
03:33In the loop we'll set lineY equal to height minus, now put some parentheses
03:41here, and going to subtract allBytes.readFloat.
03:49It gives us a floating point number.
03:51It's going to between -1 and +1.
03:52I'm going to multiply that by height.
03:56So, this will give us a value between negative height and positive height, or in
04:01other words -12 and +12.
04:05And of course, you can change the width and the height of these values if you ever want to.
04:11So, by subtracting that value from height, it's going to go up or down from height.
04:19So, after that, sprite.graphics.lineTo, and then pass in i, and then pass in
04:30i and then lineY.
04:33For lineTo you just pass in X and Y coordinates and Flash will just draw a line
04:38from wherever the line is currently.
04:40So, moveTo starts right there, at 0 and height.
04:43Then lineTo for each byte will go through to whatever i is for the X position,
04:48and the lineY which corresponds to the byte, after readFloat is run.
04:53Now, it's important to note that this readFloat method is actually what's
04:57looping through the Byte Array.
04:59The i variable is just for plotting the X position of our line, and we're
05:05getting the Y position from looping through the bytes using readFloat here.
05:11So, if we test this out, we should be able to see just the left channel in action.
05:15So, save the file.
05:17Then test the movie.
05:18You'll have to play the song to see the sound wave data over here on the right.
05:21(Music Playing)
05:33There you go.
05:35That's the left channel right there.
05:37Now, if you want to you can decrease the volume and you can watch the sound waves update.
05:41(Music Playing)
05:49Nice, looks like it working just as it's supposed to.
05:52For the right channel, I'll pretty much going to copy and paste this code and
05:55just modify it slightly.
05:57So, just copy everything below sprite.graphics.clear.
06:01Then go down a few lines and paste that code.
06:04Now, in the pasted code, right above sprite.graphics.lineStyle, I'm going to
06:10use the lineTo method.
06:11So, sprite.graphics.lineTo, then I'll pass in width and height.
06:21So, we're going to just move that line which draws a line to X of 16 and a Y of
06:3112, or whatever values we have in that for width and height.
06:35We're going to change that color from colorL to colorR.
06:39That's the color for the right channel.
06:40Again, you can feel free to mix up the colors however you want.
06:44Then when it says moveTo 0 and height.
06:46We're going to change 0 to width.
06:49When the bytes come into the Byte Array, they're actually 512 bytes.
06:53The left channel has bytes 1 to 256 and the right channel has the rest of them.
06:59So, what we're going to do is we plotted it from the left to the right for the
07:02left channel we would plot it from right to the left, for the right channel.
07:06So, we're going to start all the way the right here with that width property.
07:09So, for the For loop, we don't need to declare the variable again.
07:14We'll set i = width , so I'm going to backwards now.
07:18As long as i is greater than 0, we're going to run this loop.
07:21Instead of i++ it's going to i--.
07:24This is going to be exactly the same thing for this loop.
07:30So, we don't need to change anything inside of the loop.
07:32The last thing we're going to do is right below this loop, I'm going to have
07:36that draw a line to X of 0 and a Y of height.
07:39So, sprite.graphics.lineTo, I'll pass in 0 and then height.
07:49So, that will basically reset our line.
07:51So, save the file, and then test the movie, and play the song to see the sound wave data for both channels.
07:58(Music Playing)
08:11There is our sound wave data.
08:13So, feel free to change the colors, change the width and height, and customize
08:16this however you want.
08:19For more information about Byte Arrays and working with sound wave data, you
08:23can see Flash Help.
08:25Actually, much of the code that I show here is from the Flash help, about
08:30accessing raw sound wave data.
08:32So, you can find more information there, and you can apply it to use sound wave
08:37data in interesting and creative ways.
08:40So, remember that when you work with sound wave data, you use a Byte Array, and
08:44you use the computeSpectrum method, passing in that Byte Array.
08:51Then you can loop through the bytes using the byte arrays readFloat method.
08:56That's how to work with sound wave data.
08:58So, now you know how to work with sound wave data in the Flash Player.
Collapse this transcript
6. Adding Sharing Features
Viewing the working files
00:00In this chapter, we are going to look at sharing our application.
00:04So, let's say you want other people to embed your music player on their website
00:09or you wanted them to be able to share the URL to your music player.
00:14In this chapter, we will look at how to do that.
00:16We will start by looking at the files that we are going to be working with.
00:19First off, I will start with our XML file.
00:22This file is the same XML file we have been working with for the last few
00:25chapters, except I have added another element at the top called Share.
00:30This has an attribute called URL.
00:32It's a value of player.html.
00:37That serves as the HTML link to the music player and of course, I have published
00:42my FLA file, so I do have that player.html file.
00:46Then I have the object tag here, which you can get if you don't have
00:49the Exercise Files.
00:50Don't copy all this down.
00:52That's going to take a long time.
00:53You can publish the FLA file and then Copy and Paste the object tag in here.
00:58What you want to do is just change allowfullscreen's value to true in two cases.
01:03It's going to be in the embed tag.
01:05You are going to set it to true and the param, you will set it to always.
01:08So, that's our XML file.
01:10Let's go over to Flash.
01:14Our FLA files, what we will look at first in Flash, it's basically the same FLA
01:18that we have been working with.
01:19I've just replaced the sound wave with this sharing movie clips.
01:24If I double click the player, I can enter its timeline and I can see there's
01:27movie clip in their called share_mc.
01:29Now, it's on its own layer called info.
01:34Pretty straightforward.
01:35If you double click that movie clip, you can enter its timeline.
01:38You'll see that you have two layers and I will just expand my layer area, so
01:44that you can see the name of layers, so we have share info and the icon that's
01:48hidden behind share info.
01:50Share info has an instance name of info_mc and if you could double click it, you
01:54can enter its timeline, pretty straightforward, some set text fields, some
02:00dynamic text fields.
02:03Dynamic text field tab, instance name of embed_txt for the bottom one and
02:08link_txt for the top one.
02:11There are two Copy buttons, so we have copyLink_mc and then we have copyEmbed_mc.
02:20These are actually just very simple buttons and there's a background element
02:25that's locked here and if I select it, you can see that it's just a transparent
02:29rectangle that's basically just a hit area for this.
02:32So, when I rollover that Share button icon, then when I have to roll out of this
02:38large area in order to make it disappear.
02:41So, I am just expanding that hit area.
02:44So, back to Share, and if I hide share info, you can see that the icon, very
02:50simple it's just a bitmap image, just a little share icon and that's it.
02:56So, let's go over to Share Info.as.
02:59I already made a lot of this class, but it's pretty simple.
03:05So, I am declaring the com.lynda.audio package.
03:07So, just like everything else in this title you will need to save it in that
03:10package or in that folder called Share Info.as, import all the display, event,
03:19system, and text classes.
03:22Create for public properties shareBtn that's a MovieClip, player is a Player,
03:29linkTxt is a TextField, embedTxt is a TextField.
03:34The constructor accepts two parameters.
03:36p is a Player, s is a MovieClip, setting player = p, shareBtn = s.
03:45That's actually the whole share movie clip that contains the icon and the info movie clip.
03:51Setting buttonMode = true, setting info visibility to false.
03:56So, you will be able to see the share icon, but not the share info text field
04:01and copy buttons and everything.
04:04I have a method called init that's public.
04:06Looks like it's a lot more complicated than it really is.
04:09I am just setting the values for a linkTxt and embedTxt.
04:12We have a short hand reference to them.
04:13I am setting a text inside to the linkTxt field equal to whatever the URL is in
04:19the share element from the XML file.
04:22Then I am taking whatever is in that share element that's everything that's
04:26inside of the element, so all that object tag stuff and I was taking that as an XMLString,
04:33I know it's HTML code, but we are just reading it as XML here and that's fine.
04:38So, we get that XMLString there.
04:40So, we'll have all that code to work with inside of the embedTxt field adding
04:45an event listener to listen for ROLL_OVER for the share button and also
04:49listening for ROLL_OUT.
04:51That's going to show and hide info movie clip based on when you roll over
04:55or when you roll out.
04:56Just like you'd expect them to work.
04:58So, that's pretty straightforward and then finally the Player class and I've
05:02just added a few lines here.
05:04So, I created a public property called shareInfo.
05:07I instantiated it at the bottom of the constructor passing in this for the
05:12player and then share_mc for the share movie clip which is called the Share
05:19button inside of the shareInfo class.
05:23Once the XML is loaded, I initialize shareInfo object by calling its init method
05:30at the very bottom of the XML loaded method and that's it.
05:35So, once you've your file set up like this, you can test the movie and see
05:39that it's pretty much the same as we have been working with except for that
05:43movie clip is going to show is going to show on height when I roll over it,
05:47pretty straightforward.
05:48All right, once you are ready to go, you are ready to start adding more
05:51functionality to this applications, so that you can share it with other people.
Collapse this transcript
Selecting and copying text
00:00In this movie, we will look at how to select and copy text from the text field.
00:05So, we will start by scrolling down to the init method and at the very bottom of
00:10this method, we are going to add some event listeners to link_txt.
00:16In this area we are going to add some event listeners to our copy buttons.
00:20We are going to start in this area by adding an event listener to our copy buttons.
00:25So, shareBtn.info_mc.copyLink_mc. addEventListener and the event is going to be
00:38MouseEvent.CLICK, and the method that we will run is called copyLink.
00:44We will define that in just a minute.
00:47Go to the next line and we will add an event listener to linkTxt.
00:51So, linkTxt.addEventListener and event is going to be MouseEvent.CLICK and the
01:02method is going to be called selectLink.
01:06So, when you click on the link Text field, it's going to select that link.
01:10If you click the copy button, it's going to copy the link.
01:12So, we are going to do the same thing for the embed button.
01:16So, I am just going to copy those last two lines of code and I will paste them
01:24and in the pasted code, I am going to change copyLink_mc to copyEmbed_mc and I
01:30will change the method name to copyEmbed as well and then I am going to change
01:39linkTxt to embedTxt.
01:43I will change the method name to selectEmbed.
01:46Now, right below the init method, we'll define another private method called
01:56selectLink, receive an event with the data type of MouseEvent, void for no
02:06return data and in the selectLink method, we will set linkTxt selectable
02:14property = true, make sure that you can select it and then we will use the code
02:19to actually select part of the text field using ActionScript.
02:24Now, remember that when you are doing this you have to do it inside of a
02:27MouseEvent event handler.
02:30So, you can't just select a part of the text field from wherever you want.
02:32You have to be responding to a MouseEvent, same with copying things.
02:37So, linkTxt.setSelection and this is just basically an index space selection.
02:46So, 0 would be the first character and in order to get the last character, we
02:50can just access the property length.
02:54So, linkTxt.length, so that I will grab the whole selection inside of the linkTxt.
03:00That's all that there is for selecting a link.
03:02So, we will define another private method called copyLink, event, data type of
03:10MouseEvent, :void for no return data and here we are going to set the clipboard
03:17to copy the link in the text field.
03:19Again, you need to do this inside of a MouseEvent.
03:22There has to be some sort of user interaction in order to copy something to the clipboard.
03:27So, the method we are doing that is System.setClipboard and then it accepts a
03:35string, so you can put whatever string you want in there and I am going to put
03:38in linkTxt.text and that's really all there is to it.
03:45I am just going to copy and paste these methods and basically do this exact same
03:50thing for the embed text field.
03:52So, I am going to change selectLink to selectEmbed and I'm going to change
03:57linkTxt to embedTxt.
03:59Just copy and paste over that.
04:06Then I am going to change copyLink to copyEmbed and save the file.
04:15Now, you should be able to test the movie and roll over that little shared icon
04:23and if I click on let's say player.html and then click copy, I should be able to
04:30go back into Flash or whatever other application and then just use Command+V or
04:34Ctrl+V and then paste that code.
04:37So, that works with player.html.
04:40Let's test it one more time and it's going to confirm that it works with
04:45the embed text field.
04:46So, I will select it by clicking it, click the copy button and then paste and there we go.
04:54And so, I am just going to press Command+Z to undo that and I will save the file.
05:00Now, we have successfully set it up, so that we can select and copy text
05:05using ActionScript.
05:06So, our sharable player is pretty much complete.
Collapse this transcript
Setting up a testing server: Windows
00:00In order to test out our sharing application on our home computer, we'll need to
00:05install something called the testing server.
00:07A testing server mimics a web server, so it's basically like you have your own
00:12web server on your home computer.
00:14To do that on Windows, I'm going to use a software package called WampServer.
00:20WAMP stands for Windows, Apache, MySQL and PHP.
00:25You can install all of these services in one simple download.
00:30This is the quickest and easiest way to get a Testing Server up and running on your computer.
00:35So go to wampserver.com, and then the default page is in French.
00:41I'm going to click this British flag here, and go to the English version.
00:45And then, I'm going to scroll down I am going to click step 1 to, Download the
00:49latest release of Wampserver 2.
00:52And then, I'm going to click the link to Download WampServer 2.0i.
00:57When prompted, I'm going to click to save the file.
01:02The file will then download, and then I'll open it up when it's done.
01:08I'll choose to run the application, and then I have a security warning, I know
01:14what application this is and I trust it.
01:16So I'm going to click Allow.
01:19Click Next to start the install Wizard.
01:22Make sure that you read over the license terms before choosing to accept the
01:27License Agreement, I'll do that and click Next.
01:31I'm going to choose where to install Wamp, I'm going to leave the default
01:35location here, which is right at the C drive, so I'll click Next.
01:40I'm not going to click to create a Quick Launch icon or a Desktop icon, but you
01:44can feel free to do that if you would like.
01:48So I'll click Next and then I'll click to Install Wamp.
01:51Then Wamp will go through the installing process.
01:55Wamp is asking if I want to set Firefox as a default browser for WampServer 2?
02:00I'm going to click Yes.
02:01That's purely optional.
02:03You can have whatever browser you want as the default browser.
02:07And now it's asking me to specify an SMTP server.
02:10Right now, I'm not really concerned with that because we don't need this feature
02:13for testing our sharing application.
02:15So I'm just going to click Next, and leave it at the default.
02:18And then I'm going to Launch WampServer 2 now, by leaving that box checked and
02:22clicking the Finish button.
02:23Now, you'll need to have WampServer running before you can use its services.
02:31So make sure to remember that whenever you are going to test an application in the future.
02:36And you can find Wamp with your other program files of course.
02:39Another security warning pops-up, I'm going to click Allow since I know
02:43which program this is.
02:45The bottom-right corner of my screen, you could see that WampServer is launching.
02:49You could tell that it's ready when the whole icon is White.
02:53To test to make sure that it's running properly.
02:55I'm going to create a new tab in Firefox.
02:59In the new tab browse to a http://localhost, all lowercase.
03:12When you go there, you should see this page, not some kind of error message.
03:17If you see an error message, make sure that WampServer is running, and you see
03:22the icon in the Taskbar.
03:25So now I have confirmed that WampServer is running.
03:27I'm going to go to my C drive, and I'm going to go into the wamp folder.
03:33Anything that you'll need to test on your testing server will need to be in
03:37here, specifically it will need to be stored in the www folder.
03:42This acts as the root of your testing server.
03:45So this index.php file is the file that we're looking at when we go to localhost.
03:51In here we will create a file called ldcaudio, and we'll store the sharing
03:57application files in there.
03:58So I'm going to right-click, create a New Folder, call it ldcaudio, all lowercase.
04:07And at this point you just copy the files for this next exercise into this
04:13folder, and then you're good to go.
Collapse this transcript
Setting up a testing server: Mac
00:00In order to get our sharing application working on your home computer,
00:04you're going to want to install something called a testing server.
00:07A testing server mimics a web server's functionality on your home computer.
00:13Before we download a testing server, I want you to go to System Preferences.
00:19In System Preferences, go to Sharing and make sure that Web Sharing is off.
00:25So it should be unchecked.
00:27If it's on, it could cause some problems with the exercise that we'll be doing.
00:30So once you have done, you can close System Preferences, and open up your web
00:35browser and then go to mamp.info.
00:40MAMP Server is the fastest and easiest way to get a testing server up and
00:48running on your Mac.
00:50MAMP stands for Mac, Apache, MySQL and PHP.
00:56So you get all of these service in one easy install.
01:00So when you're at the MAMP website, I'm going to click to download the
01:03free version of MAMP.
01:05That's the gray one.
01:06This takes me to the download page, and again I'll click to download MAMP, not MAMP PRO.
01:14You could download MAMP PRO.
01:14It has more services than what we need for this application.
01:18You're then taken to the download page.
01:21It actually already downloaded it to my computer.
01:24So I'm going to open up my Downloads folder, and in there I'll open up MAMP.
01:33Now, I'll install MAMP by clicking and dragging the MAMP folder to the
01:37Applications shortcut.
01:41And once it's done copying, you can launch MAMP through your
01:45Applications folder.
01:46So I just find the MAMP folder, and then launch MAMP.
01:52At this point, you may want to click and drag MAMP down to the dock for easy use.
01:57But I'm not going to, I'm just going to open the file.
02:01This is the file that I trust that I downloaded, so I'm going to click Open, and
02:04that will launch MAMP.
02:09And what I want you to do is go to Preferences.
02:12Go to the Ports tab, and then click Set to default Apache and MySQL ports.
02:18So Apache should be at Port 80, and MySQL Port 3306.
02:23Go to Apache, and then you're going to see Document Root.
02:29Click Select, and we're not going to use the default.
02:33You're going to select your Sites folder that's going to be in your User folder,
02:38and then click Open.
02:39So that's going to be the Document Root.
02:42Click OK, and then MAMP will relaunch.
02:47It'll ask you to authenticate using your user Name and Password, so I'll do that.
02:50And you should see green lights for the Apache Server and the MySQL Server.
02:57Once you have that, minimize MAMP, and open up your web browser again.
03:03In your web browser, go to http://localhost.
03:15You should see this page.
03:17This is the default sites page on your Mac, unless of course you changed it.
03:22So now that we have this we're good to go after one last step.
03:27Go on to your Sites folder, and create a folder called ldcaudio, all
03:35lowercase as I have here.
03:38In that folder, copy the files for the next exercise.
03:42As you could see that I've done right here.
03:45Once you have those ready to go, you're ready to start working with the sharing
03:49application, and seeing it an action.
Collapse this transcript
Testing sharing features
00:00In this movie we are going to test our sharing application.
00:03Before you go forward it all, make sure that you have your testing server
00:08installed and running.
00:10I am going to go to my testing server folder, on my Mac its in my Sites folder,
00:18and in there you should find your ldcaudio folder.
00:21Remember from the PC you can access it through your C drive in the wamp folder,
00:27in there you will have to find the www folder, and in that folder you should see
00:33ldcaudio and your files.
00:35The first thing that you need to do is go to your Player.as file, find the line
00:42of code where you load data.xml.
00:46Here instead of loading the local file, you want to give the absolute URL.
00:53So, instead of data.xml, it's going to be http://localhost/ldcaudio/data.xml.
01:08Of course when you upload this to your web server you are going to want to put
01:13the full path to the file, so you should be able to put this URL in your web
01:17browser to find your XML file.
01:20Then I am going to select everything up until the forward slash after
01:28ldcaudio and copy it.
01:30We are going to be pasting this over and over again, so I want to make sure I
01:34don't have to type out the full thing every time.
01:37Save the file, and very important here, test the movie.
01:41So, you are going to need the output a SWF file with that new URL in it.
01:47It should work just as usual.
01:49(Music Playing)
01:53If you have any problems, make sure that your testing server is up and running
01:58and that there is in fact localhost/ldcaudio/data.xml.
02:04So you can test this URL in your web browser to make sure it pulls up your XML file.
02:09Now that I have created those files, I don't need the FLA open any more.
02:16Also you want to make sure if you are having already to output an HTML file from
02:20that, so you should publish the file.
02:22Now let's open data.xml in the Text Editor.
02:28Notice all the URLs are relative, in other words they don't contain the absolute
02:33URL which concludes localhost/ldcaudio.
02:38So we are going to need to paste all of these URLs in, so right before
02:41player.html I am going to paste in my long URL, and then in the param value I am
02:49going to paste it in the object tag.
02:51And then in the embed tag I am going to paste it in for the source attribute.
02:56And then for each song I will paste it before the song file name.
03:07So, once you have done this for all the songs make sure to save the file.
03:14So now Flash is going to be looking for these in the absolute location, not the
03:20relative location because you need the absolute location when you are going to
03:24be sharing a file because the person is going to embed the SWF on some different domain.
03:30It's still going to load from your side, but you are going to need to this in
03:34order to make it work properly.
03:36So you can close data.xml, and at this point you should be able to open up your
03:43web browser, paste in the code from earlier, add on player.html and then hit
03:52Enter or Return to see your application.
03:55So, you can play the file and everything should work fine.
04:00(Music Playing)
04:04And you can see that it's working great.
04:06That link is working properly.
04:08See that link is updated right there in that link section.
04:11So of course I could click the copy button and then paste that in my web browser
04:16and then try it again, and it works properly.
04:19(Music Playing)
04:20But let's check out the embed option.
04:24So what I want you to do is just click in that embed field and then click the copy button.
04:28So now we have successfully copied the embed link.
04:32Now let's create our own HTML file and test it out.
04:37So what I am going to do is I am going to close this folder here and I am going
04:41to create a file on my Desktop.
04:43I am going to use Text Editor.
04:45You can use Notepad on the PC.
04:46So I am going to save this on my Desktop as test.html, make sure to use the HTML
04:55extension and also make sure that you are using Plain Text writing mode and not
05:00Rich Text writing mode.
05:02Now here I am going to create a ridiculously basic HTML file.
05:06So I am going to create the opening HTML tag, the closing HTML tag, opening and
05:13closing Head tags, the opening and closing Body tags.
05:22And inside of the body, I am going to paste the code that I copied.
05:27So there is that object tag in there.
05:29So we will save the file, and then here is the magic.
05:35I can test this and notice that it's not on my testing server, I can just drag
05:39it to my web browser, open up the file.
05:42You can see that the SWF file is successfully embedded.
05:46I can play the songs and everything.
05:48(Music Playing)
05:52And it's all being loaded form the testing server.
05:56So, essentially you can put this file anywhere on the web and it will embed that
06:01file into the application.
06:03Now of course you don't want to put it on the web when you are using the testing server.
06:06You want to put it on your actual web server and then the share URLs will work,
06:11and people can embed your music player in their website.
06:14So now it's time to take a break, pat yourself on the back and congratulate
06:21yourself for creating an amazing shareable application that people can embed on
06:27their website anywhere on the web.
Collapse this transcript
7. Viewing an Audio Player Application
Viewing the finished player
00:00In this chapter we are going to look at an application that utilizes all the
00:04techniques that you learned throughout this title.
00:07Now, my purpose isn't to teach you how to make everything in here from Scratch,
00:12I just want to get you thinking creatively about what you can do to use what you
00:17have learned in this title.
00:20So again, we are going to be going over some of the code in this application
00:24but not everything.
00:25I am really just showing this to you, so you can get a feel of what you can
00:30create with the things that you know right now.
00:34So here I have my files on my testing server.
00:37So if you are going to follow along and you have the files, make sure your
00:40testing server is running and that all of these files are in the right place
00:43that is the ldcaudio folder of your testing server.
00:47So I have this little icon that says Launch Audio Player, when you click on it,
00:52the Audio Player launches.
00:53So there is some Album artwork and if you roll over the bottom, you'll see that
00:57the Playlist comes up.
00:59Now I have that initial thing that you click because in order to load
01:05images externally like this one I have here, you need to have some user interaction first.
01:10So the user has to click in order for it to initialize loading and that's more
01:14of a security precaution for the Flash Player.
01:17The reason why I do like that is because I want to have this be an application
01:22that can work entirely off of XML data instead of requiring a person to go into
01:27Flash to change it and that's why I put that little screen at the beginning.
01:32So we see this is an album, The Jellybricks Goodnight to Everyone.
01:36At the bottom of the screen, we have our player, when you hover over it, the
01:41list comes up and you could select a song that you want to play.
01:43(Music Playing)
01:44Now, you will notice a lot of things may look familiar that we have created, we
01:52have the Play button and the progress bar, the time, volume, sound waves,
01:59sharing object, all of that.
02:01I have added this list, so that you can control the Playlist through Scrolling
02:06menu instead of just clicking back and forward.
02:09This way we can see the information for each song like the name of the song etcetera.
02:13There is also a little iTunes button, which if you click, will go to that song in iTunes.
02:19So I am going to scroll down and then click the iTunes icon for More to Lose.
02:24Now, watch iTunes launch and it will go to this album in iTunes, and then hunt
02:29down the More to Lose song.
02:31So I can listen to the song through iTunes if I double-click it.
02:34(Music Playing)
02:42So you can see this is a pretty full-featured application.
02:47So we have iTunes connectivity, external images loading, it's all powered by XML data.
02:53So if you wanted to change anything that you work with it, and you just
02:56change the XML file.
02:58Now, throughout this chapter, we will have a quick walk through of this application
03:03and you will see some of what I did to create it.
Collapse this transcript
Walking through the application
00:00In this movie, we will briefly walk through the application that I demonstrated
00:04earlier in this chapter.
00:06We will start by looking at the XML file.
00:09You will notice that I added a few things.
00:10In the opening Album tag also known as the Root element, I added an attribute
00:17called the Cover that holds the URL to the Album cover.
00:19So you can swap this out, if you wanted to put in a different album.
00:22Let's say you have a band, or you are working on a project for a band, or
00:26something, you could put that in here.
00:29And here is the link that contains the link to the album.
00:33I am not actually using that in my application but I have it there just in case, I want to.
00:38Notice this, this big iTunes URL.
00:40I will show you how to get that URL in just a few minutes.
00:44So we have a share URL that you are familiar with, and all the songs are exactly
00:49the same as they were before, except they all have an element called Link,
00:53another iTunes link.
00:55Let's look at how to get those links from iTunes.
00:58It's actually really simple.
01:00I am going to tab over to iTunes and then I am in the Jellybricks' Goodnight to Everyone album.
01:06Of course, you can do Search the iTunes Store, if you want to find it, or you
01:09can go to any other album that you would like.
01:12Here is what you do.
01:13You just right-click.
01:14So if I want to link to the album, I right-click the album artwork, I can choose
01:18Copy iTunes Store URL.
01:22And then, of course, I can open up a web browser, paste the URL in, and it will
01:27take me to the correct place in iTunes.
01:30If I wanted to link to a particular song, I could right-click, say Put It Down,
01:35for example, choose Copy iTunes Store URL and then go to my web browser,
01:45paste in the URL, and I am taken directly to that song in iTunes.
01:49So, that's all you had to do to get to iTunes links.
01:52Take those, put them in the XML file, and there you go.
01:57Links, so people can buy songs in iTunes.
02:00This could be a great tool for a band because you can make money with
02:04this little Flash app.
02:06So, let's go over to Flash and look at some of the ActionScript that I used to
02:09create this application.
02:11So here is that button that I showed you from the beginning.
02:14I am not going to go inside of the symbol because it's just really simple.
02:18It's just a button.
02:19I called it play_btn, and then here I have the music player and then behind
02:26that, there is a list box.
02:28This list box is something that I showed how to create in my user
02:32interface elements title.
02:34So if you want to see how to create that from scratch.
02:36I suggest going there.
02:38Of course, you won't see how to add the iTunes links in that title.
02:41That's something that added in this title.
02:43But I challenge you to figure out how to do that.
02:46Let's go through some of the classes.
02:48Here is the Player Document class, which is the new class I created to serve
02:53as the document class.
02:56It basically controls and connects the list and the player.
03:01It controls the animation of the player, moving up and down, fading in and
03:04out using Tween Light.
03:08It's pretty straightforward, and the main thing that I did here that you need to
03:12take a note of is that I control all of the model interaction through this
03:18player document class.
03:19So I kind of took it out of the player for the most part and put in the document
03:24class so, I can connect the model to the list and the player and both of them
03:28respond when you make a change on one or the other.
03:36So, here is that code.
03:37Once you look it over, and you can feel free to pause the movie and copy it
03:41down if you would like.
03:43Again, this isn't going to be all the pieces of the puzzle.
03:46If you want to build this application from scratch, this is just going to be
03:51able to get you started.
03:51So, whenever you change the element in the list, the player is updated.
03:54When you change a song in the player by a song ending, then the list is updated
04:00because they both control the model.
04:02So, I go to my player class and my player class now initializes once the XML is
04:07loaded in the player document class, and it runs a method called Init and that
04:12basically starts out everything.
04:14So, we set the model in there, getting that from player document at the
04:18Event listener, listening for the model change, which updates the song
04:23whenever the list is changed.
04:26All of this should look pretty familiar because these are things that we already
04:28look at throughout the rest of this title.
04:30So I am playing the song, and then I have this song finish method and let me
04:43show you how I check to see if a song was finished.
04:46This is actually something that's really important to note.
04:49The Flash Player is sort of the infamous for not responding properly when a song is finished.
04:56I have seen a lot of people that have complained that when a sound is sampled at
05:02a lower rate, the Sound Complete Event doesn't trigger at the right time, or it
05:07never triggers at all.
05:08So that's a pretty big problem.
05:10So, what I encourage you to do is to make your own Sound Complete Event and
05:15here is where I did it.
05:17In the progress display class, I change the class to extend the event dispatcher
05:22class so that I can dispatch events.
05:25So what I do is when the song is playing, I am constantly checking to see if the song is done.
05:34So here's my code right here.
05:37Here's how I do that.
05:38I check to see if the progress of the song, that's the progress string, is equal
05:45to the length string.
05:46So if they are equal, in other words, the song is at the end,
05:50so 340 for the progress and 340 for the length and to double check, I make
05:58sure that the sound is completely loaded because the sound could have just started loading.
06:02It'd be 10 seconds and it only have 10 seconds loaded and triggers this event.
06:06I don't want that to happen.
06:07So, I make sure that the sound is completely loaded and it's all the way to end.
06:10So I am using that time to check that.
06:13Now if you want to get more precise, you could check it would milliseconds
06:16or however you want.
06:17But this is just how I did it here.
06:19When that happens and both conditions are true, I dispatch the Sound Complete Event.
06:25That's event.sound_complete and then I listen for that in the player class and
06:31run the song finish method.
06:34Song finish method disables progDisplay and goes to the next index of the model,
06:42or loops all the way around depending if the model is done.
06:45Now remember the model at the end of the set current index method dispatches
06:50that model change event as well.
06:52So, that's what I did to the classes that we worked within this title.
06:56And again I switch up the list class just a little bit.
07:00So if you are trying to make this app from the UI title, note that you are
07:05going to have to make some tweaks here and there but I am going to leave that challenge for you.
07:09I want you to get practiced, creating complex applications, and I also want you
07:13to send them to me when you make them.
07:16I have gotten emails from a few of you, seeing some great applications that
07:20you have developed.
07:21I got to tell you I am really proud of you for sending those to me, and for
07:24taking those challenges.
07:25So, feel free to contact me through my website chadandtoddcast.com or through
07:30lynda.com and share with me what you create using these techniques that you learn in this title.
Collapse this transcript
Conclusion
Goodbye
00:00Well, you've reached the end of this title.
00:02I hope you had a good time learning about how to work with audio in Flash CS4.
00:07Take a moment to think about all the things that you've learned in this title.
00:11You learned how to load external audio files, how to work with an XML
00:14playlist, how to control volume, sound progress and even share your
00:19application over the web.
00:21I'll leave you with this challenge.
00:24Take what you've learned in this title and apply it to making your own
00:27unique application.
00:29And if you want to, you can feel free to send me a link, so I can check it out.
00:33You can reach me through my website which is chadandtoddcast.com or of
00:38course, at Lynda.com.
00:39I'll see you next time.
Collapse this transcript


Suggested courses to watch next:

Flash Player 10 New Features (4h 0m)
Lee Brimelow


ActionScript 3.0: Working with XML (2h 27m)
Todd Perkins


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 100,984 instructional videos.

start free trial learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 1,943 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.


site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked