Now, we are starting to get pretty much the basic structure of our game. We need a couple of nice bells and whistles tossed in here. In fact, one of the things I want to add is a bell or a whistle. We need to sound object that we can use to help us figure it out that we have actually popped a bubble, and we probably should be doing some scoring in here as well. So, let us set those two things up next. Now, I think this might be the first time in the lessons where we have actually tried to cue a sound with action script. But I will bet you can guess how we are going to do it. We are going to be using a sound object for that. Down under movie, we have got, oh no, I think it is under media, yes, there we go.
We have got a sound object which of course has methods and properties and very importantly, we are going to need to instantiate a new sound in order to control it. So, let us go about setting one of those up. We have made new objects before, so, we will set this up in our create object section. I will just make a new line and we will create a sound object. Once again, I will start with the bar keyword. I will put S and D at the beginning of this one so I know what type of object it is and we are going to call this pop because that is the sound we are going to pull in here. It is going to be a bubble popping sound. I will declare that as a sound object and I will use my new keyword so that we can make our new sound object.
Now, as before, we have made a new empty sound object. We need to fill it up. Probably the first method we are going to use, I think it is the first one in here is a touch sound. That is where we can actually fill a sound into an empty sound object. So, I am going to do it right up here where I create the object. I am going to load the sound that we are going to use into it. Now, over in our library, you can see that we have already got a sound imported, it is a wav file called bubble popped. But in order to be able to access that sound out of the library, I am going to need to have some kind of an identifier for it.
Now, we have dealt with these ones before with the font object in the previous lesson. But basically, in order to make sure that this element gets exported with the swift file so that it is ready for use, I will need to set up the linkage on it. I will just click on the object. You can go up to the options menu or you can write or context click and it will go down to the linkage item in the menu. Now, you can see what we are doing, we are going to be exporting this object so the action script can use it and we are going to need to give it some kind of an identifier name.
Now, a lot of times, I will just leave the original name in there but just to make things easier, I am going to change the name to pop so it is a little bit easier to type and I can name it whatever I like as long as you make sure you remember what the linkage name is. You can see that it is not appearing out here in the library at all. Now, we are actually ready to use our attached sound method because we can refer to that element by its ID name. I will start off by typing in the sound name that we have made, SND pop. I will do its attached sound method and you can see we just put in the ID name there. I will just type pop into that and we will now have filled that sound into our sound object.
Now, looking down the list of methods, we have got all kinds of methods that tell us about how big the sound is or we can change depending or the volume. But what I am most interested in is this two at the bottom, start and stop. Now, in most cases, I do not need to stop the sound and I believe this one is a very short sound; it should be just a popping noise. So, we are just going to use the start method to be able to start playing the sound. And we can pretty much place that wherever we would like to in the program. I am going to look for the place where we set our bubble up pop so to speak, that is down here where I hit test method as checked. And right now, we have the movie unloading. All we need to do is play the sound at this point by specifying the sound and calling off the start method. Let us give that a quick try. Now, I get my pin out of the way here, make any game. And we have definite confirmation that we have hit each one of the pins with that popping noise added to the unload movie.