Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
Through several hands-on tutorials, instructor Todd Perkins shows how to best build dynamic, streamlined sites using Flash CS3 Professional. Learn how to create custom keyboard shortcuts, apply advanced text techniques such as animating scrolling text with custom easing controls, and using advanced animation techniques. Flash CS3 Professional Beyond the Basics covers many challenging features, including adding complex interactivity to a Flash CS3 project and getting Flash content on a phone. Exercise files accompany the tutorials.
Now we're going to start working in our Mp3Player class. If you're following along with the Exercise Files you're going to need do what I'm doing right now and that is click the Settings button in the Property inspector with everything deselected, we're going to have to reconnect to our class. Because this file is in a different position, we are linking to different classes so choose the Settings button for ActionScript version. What I'm going to do is select the current Classpath and delete it, click the Browse to Class button and then I'm going to go to the Chapter 5 folder, Start folder and then choose the Classes folder and click the Choose button.
Then I'm going to click OK. Now click OK to exit the Publish Settings window as well. So for those of you following along with Exercise Files you're going to become very familiar with that process throughout the rest of this chapter. If you're not following along with the Exercise Files, then you may not need to do that process unless you're working in a different folder for each movie. So let's start writing our Mp3 Player class. Select the first keyframe of the Actions layer and open up the Actions panel by pressing Option+F9 on the Mac or F9 on the PC and at the very bottom of all the code we're going to create a new variable called mp3Player, with capital P for Player, and the data type will be Mp3 capital M and then Player with a capital P, and on the same line of code we'll set this variable equal to a new instance of the Mp3Player class.
Our Mp3Player class is one of the classes that we're going to be working with and that we looked at in the last movie. What we're going to do is pass in all of the variables that we've created into our Mp3Player, so that when we create it, that Mp3Player class can work with all of these values. I'm going to pass these values in, in a particular order, so just note the order that I'm typing them. The first value we'll pass in will be songs and then volMC, both M and C are capitalized, then playBtn, then pauseBtn, then nextBtn, then previous Btn, prevBtn, with capital B, artistTxt with a capital T, songTxt with capital T, progBar and progSlider.
And that was a ton of values passed into that Mp3Player object. You'll really want to take a second to look over the code passed in when we created the new Mp3Player to make sure it matches mine exactly, that all the variable names have the same casing and spelling as the variables we created on lines 3 through 12 in my code. Once you know that everything looks okay let's close the Actions panel and then we'll open up that Mp3 Player for Class file. So choose File, Open, find the Chapter 9 folder in the Exercise Files folder then the 05 folder and the Start folder, and then we're going to go all the way down to find our Mp3 Player file.
So go inside of classes, com, lynda, audio, mp3 and then open up the Mp3Player.as. Inside of this file we are going to create variables to hold all the values passed in when an instance of this class is created. Some of the variables will be public and some will be private. We'll talk more about the variables and more about what public and private means as we create these variables. So inside of the public class Mp3Player code and above the constructor function, which is the function called Mp3Player let's create a private variable called songList with a capital L and the data type for that variable will be Array.
Lets talk about what the word private means. Private means that this songList variable is known only to this class file, and so I can only reference this variable from this class file. I can't reference it outside of the class file in FLA file, I can't reference it from another class file. So that's what private means and public means you can access that variable from your FLA file or from another ActionScript class file. Let's go to the next line and let's create a public variable, so type public var and we'll create a variable called soundLoader.
It's going to be an instance of the SoundLoader class. The SoundLoader class is not a pre-built ActionScript class, it's something that we're working with throughout this chapter. Our SoundLoader object here will load our sound. We're naming this variable public so that we can access the playing sounds from our other ActionScript files, and the rest of the variables that we are going to create are going to be public as well, so they can be accessed from other files. So we create a public variable, called volControl, capital C.
and the data type is going to be VolumeControl, and this variable is actually going to be an instance of our VolumeControl custom class. We'll talk more about that when we start working with that class. We'll create another variable, we'll call this playPause,with capital P for Pause and the data type is going to be PlayPause button and this is also going to be instance of one of our custom classes which is PlayPause button. We'll create another variable, and we'll call this variable progSlider with capital S and this is going to refer to our Instance of the ProgressSlider class, so type colen and for the data type we'll type ProgressSlider with capital P and a capital S.
We'll create one more variable called skipButtons and the data type for that will be SkipButtons. And that will be an instance of the SkipButtons custom class that we created. Let's go down a few lines and now we'll create a few more variables that are going to sort of mirror the variables in our FLA file. Once I've created them we'll talk about what they are and what they represent.
So here are some variables that mirror our FLA file. First we have playBtn which represents the Play button, pauseBtn represents the Pause button, volBar represents the Volume Bar movie clip, nextButton represents the Next button, previous Button represents the Previous arrow button artistText represents the Artist Text field, songText represents the Song Text field, Progress Bar represents the Progress Bar movie clip and dragSlider represents the draggable area of the progress bar. Remember the inner FLA file, we passed in several different values to our Mp3Player class. We'll now need to accept those values here in the Mp3Player Class file, so put your cursor in between the parentheses after Mp3Player in the constructor function and mine's on line 28, then we'll need to accept all those parameters in the same order that I type in here. So type songs, it's going to be an Array, vol will be a MovieClip, representing the VolumeBar Movie Clip, pl will be a SimpleButton representing the Play button, pa will be a SimpleButton representing the Pause button, nxt will be a SimpleButton representing the Next button prev will be a SimpleButton representing the Previous button, aText with a capital T will be a TextField representing the Artist Text field, sText with a capital T will be a TextField representing the Song Text field slider will represent the progress bar Movie Clip and drag will represent the draggable element inside of the progress bar Movie Clip.
The next thing we're going to do is capture all the values passed in as parameters where a new instance of the Mp3Player class is created and assign those valuables to the variables that we created inside of this class. So put your cursor inside of the curly braces for our constructor function. I'm on line 30 in my code and now we'll connect the values of our variables inside of this class to the parameters passed in when a new instance of the Mp3Player class is created. So I'll write the code and then I'll explain how it works.
So now we set up all of our variables and variable values for our Mp3Player class. Let's save this file and just test the movie in our Mp3_Player.fla file to make sure that everything is working properly. So choose File, Save to save the file. You can check for any errors in your Mp3Player.as file by clicking the Check Syntext button at the top of the screen and Flash tells you "no errors", that's great, and then we actually don't have to return to the FLA file to test the movie, we can actually test it from here.
Only if the target is the appropriate FLA file, so look at the top right of your screen inside of Mp3Player.as and if the target is 05_MP3_Player.fla or the FLA file that you're working in, then you can test the movie from here. So it's Cmd+Return on the Mac, Ctrl+Enter on the PC to test the movie. All we're looking for is no error messages. So we test the movie, we don't get any errors, I'm going to close the Preview window and there we go. We've set up all the variables for our Mp3Player class.
There are currently no FAQs about Flash CS3 Professional Beyond the Basics.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.