Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
What I want to do now is I want each one of my thumbnail buttons to load in the correct image when you click on it. It will load in that image right inside of this UILoader. Okay, so the first thing I need to do is give each invisible button a unique instance name. So I am going to select this first button here and in my Properties panel I am going to give it an instance name of port1_btn just like that and all of them are going to follow the same pattern. So I am going to copy that instance name and just paste it for the next button and just change this number to port2.
Again, this will prevent me from mistyping if I just paste in the instance name and change that one number. Last one, port6_btn. Now they all have instance names. All right, so far, so good. I am going to go ahead and select this first button and I am going to go to Window and I am going to open up the Code Snippets panel. Because for each one of these buttons what I am going to do is I am going to add an event handler.
That's this folder right in here. Notice I am going to select Mouse Click Event. So I am going to add a generic mouse click event to that button and all I need to do is double-click. Now it tells me that I can go ahead and add my custom code in a new line after start your custom code below is stated. So here it is, notice there is this trace statement, which just tells me that this button gets clicked on, and that's what I am going to start with is just sort of modifying the trace statement.
So port1_btn is what gets clicked on, so I am just going to copy that word and paste it right in here. So what this does is this is just going to give me a trace statement that's going to appear in my Output panel, saying that I clicked on this button. So I am going to do that for all of the buttons. I am going to select the second button, add a mouse click event for port2_btn. I am going to make sure that we have a trace statement for it. For port3_btn again I have just added another mouse click event. For port3_btn I can copy that instance name and paste it right in here for this trace statement so I know when it gets clicked on.
I am just double-clicking in this gray bar to hide the actions. Do it again for the fourth one. I can add that as welll, that mouse click event just like that. So I am starting to set-up the code for this little gallery. Add another mouse click event, port5_ btn just like that, hide that panel and then the last one double-click mouse click event, port6_btn, just like that.
Okay so I have just added six mouse click events, and they are all associated with these thumbnails, and I can scroll up and start to see all of it and notice how it adds all of these comments as well, which I really don't need most of these comments. I don't need six copies of the instructions so I can just start to delete those comments just like that. It's going to make my code easier to read seeing there is less within my Actions panel.
So here is all of my buttons. So far so good. I will just do a Control > Test Movie to test this out. I have my skeleton function set-up if you will. Go to my Portfolio section, and now when I click in my Output panel, you should see those trace statements appear, one through six. Perfect. Everything set up. So my next step is to target this movie clip which happens to be my portfolio background movie clip, because inside of it I also need to target this UILoader and for this UILoader, I need to change that content.
So let's take a look at that. Let's close my Actions panel, go back to my Timeline and if I select again, this is my Portfolio background, just like my Properties panel says. It's my Portfolio background. So I need to give this a specific instance name, and I will just call it portfolioBkgd, and I will just copy that. Okay, so I have targeted this movie clip. Now I am going to double-click it to go inside of it, and then I am going to locate this UILoader.
Remember, I have these other layers locked to allow me to select the UILoader. It also tells me in the Properties panel that I have the UILoader selected. Now what I can do is give it a specific instance name. I am going to call it mainLoader just like that. So far so good, but for this mainLoader, what I want to do is I want to change the source to the appropriate image. So I am going to change the source parameter and redefine it. So I am going to go back to scene 1.
I am going to go where that code was added, because all that code was added was right here in Frame 61. So I am going to go to Window > Actions and here is all of my code. Okay, now I can go ahead start adding on a new line the code I need to add. So I am targeting the portfolioBkgd, and then I am going to type a period because inside of that portfolioBkgd is the mainLoader and what I want to change with that mainLoader is the source.
I want to change its source and make it equal to something else entirely. What is that something else? Well, it's going to be another image, but I need to make sure that image exists. So I am going to go into the ExerciseFiles folder, assets, and I am going to locate this images folder, and these are the six images that I want to locate. I am going to go ahead and copy them and I need to put them in the images folder, Chapter 06/03 Begin.
I am going to put them in this images folder here, and I will paste them in. But what's important to note is that my Flash file is right here, and I need to make sure my images exist within a folder in the same location within that images folder. So I am targeting port1, port2, port3, so on and so forth. So lets go back into Flash. For port1_btn I am going to target the images folder, port1.jpg, just like that.
It looks pretty good. So in fact, I am just going to copy this line because I want to do the same thing for the port2 _btn, but I want to target that second image just like that. Same thing for this third image. This button is actually going to load in that third image right there. Again, it's just a copy and paste. Just be aware of what button you are referring to.
So port4_btn. Just beneath the trace statement for each one I can target that new image. Lastly, port6_btn that button is going to open up that jpg. All right, everything looks good so far, but the true test is of course testing the movie, and I will click one the Portfolio section. I am still going to get my trace statement pop-up but if I click on this second image you can see it load that it still gives me this trace statement, third image, fourth image, fifth image, sixth image.
So now my gallery is completed. Each time I click on a button, it dynamically loads in the correct image. All those images are external from the main Flash file, so it keeps my main Flash file small while still giving the user the ability to load in additional images.
Get unlimited access to all courses for just $25/month.Become a member
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.