Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
I'm now going to display the appropriate content from the thumbnails and I want to make everything XML-driven, because currently how this is set up is this image is hardcoded in the Flash file, so is this text, as well as the description. So I want to take care of that first. Also notice, as I come down here over these thumbnails, I need to implement the hand cursor, just so users know that these are buttons. So I need to make these movie clips work like buttons.
Now, if I do select one of these or any one of these, notice how it displays content from this very first image. So, I need to make sure all this information is being pulled from the correct XML and it's not hardcoded, because believe it or not, this information, as you click, is all hardcoded, pointing to that first image and its related text. Let me close that. I'm going to go into my portfolio file.
The first thing I'm going to do is I'm going to make sure this UILoader does not reference that basketball image. So I'm going to go to Window, down to Component Inspector, and right in here, this is what I mean by hardcoded. I would have to actually open up Flash and type in a new name, if I wanted to change this. That's what's meant by hardcoded, but just, all I need to do is get rid of that and that's no longer an issue now, because I don't want it to display anything when you first go to the Portfolio section.
Next thing I need to do is delete the text in these text fields, right here and right here. I do want to make sure that this text, in the Properties panel, that the Behavior is Multiline, because since I'm going to be loading in XML, I could have multiple lines of XML content. So I want to make sure this is set to Multiline. So, another thing I need to do is make sure this button is pressed as well. So I want to render text as HTML. All right! So that's looking pretty good.
Those two have been cleared out, as well as the image, and of course, that information doesn't show up. Okay, now I'm going to go ahead and fix this issue. Those movie clips, well, I want them to look like buttons or at least act like buttons. So, I'm going to select the first frame in the AS layer and I'm going to go to Window, down to Actions to open up my Actions panel and I'm going to pin my code, just so it doesn't move if I select something else. All right.
So right in here, in this loadThumbnail function, this loadThumbnail function gets called many, many times, each time where the thumbnail that gets loaded in. What I want to do is I want to make my all thumbnails act like a button. That's as easy as typing allThumbnails.buttonMode, capital M, = true. So, I'm saying, "Hey, you know what? I know you're a movie clip, but work like a button." So, give me the hand cursor and everything should be okay.
So I'll do a Test Movie. Now when I roll over these, sure enough, I get that hand and it's looking good, but I still have this issue of all of these thumbnails displaying wrong content. So let's take a look at that. Right in my loadThumbnail function, right down in here, when you click on the image, this is the hardcoded part. So it's pointing to the array, but it's taking the very first element and displaying it. So, this stuff has to go.
So what I want to do is I want to create some variables, and I'm going to create some variables right in here. So not inside of the Event.COMPLETE, EventListener or anything, but I want to write this code just above that and they are going to be variables. So these variables are going to hold the specific array information. So var thisLargeImage is going to be a String, and it's going to be equal to the largeImageArray, and then I do my two brackets.
Since this is an array, I'm going to do these two brackets, and just like I'm getting the thumbnail image array, the appropriate image number, I want to do the same thing right here. So it's just a matter of copying that line and pasting it right in here. I also want you to confirm that this LargeImageArray is spelled correctly, so up at the top of the code, largeImageArray is right there. So I want to do the same thing for the titleArray. So I'll just copy that, scroll down and create another variable.
This title is also a String and it's going to be equal to, and I'm just going to paste in what I just copied, titleArray. I want to do my brackets and within my brackets, I'm going to copy and paste in imageNum. Next up, I have, at the very top, if I scroll up to the top, descriptionArray. So I'm going to copy that again, scroll back down and type in thisDescription, and it's a String, and it's going to be equal to, add descriptionArray, my brackets, and then that image number as I copy and paste it.
So this actually stores the appropriate info for the thumbnail, regardless of what number thumbnail it is. So these variables store that information. Now, I need to use these variables. So thisLargeImage, I'm going to copy that, and where I want to put it is right down in here, for the source of the largeUILoader. So right in there, I'm going to go ahead and paste thisLargeImage.
Same thing for the title. I'll just do a Command+C and for the selected title, I'm going to make the text equal to thisTitle. Same thing for the description. I'm going to copy that variable and paste it for the text property for the selected description. All right! Test the movie. So, I'll just go ahead and click on one of these and it displays the appropriate image. So it's working great now. All of this content is coming from the XML.
There are a couple issues, it looks like. If you take, for instance, this description right here, notice that there is some HTML in there, some HTML code. I point that out, because you can have HTML code in your XML file, some basic HTML 1.1 code. So links, making a word Bold, things like that, but it's really appropriate for this because you might make a website design have an image of it in the center area. You want to give the user the ability to click out to that specific website.
So I need to render this HTML in Flash. So I'm going to close this file, and again, I'm going to just minimize that Actions panel by clicking that gray bar and I'm going to select this text box, because I want to point out that I need to make sure this is set to Render text as HTML. I'm going to open up my Actions panel again. The last thing I need to do is type in htmlText. It changes colors, confirms that it's typed correctly, and now Flash will render out this text as HTML text.
So let's run this, Test Movie. Now if I go into this take flight image, I can see the HTML code is gone and it gives me a link. So I have a hand cursor, and if I click on it, it's going to take me out to that specific site. So again, all of this content is coming from the XML. I can easily add to the XML, all I want to remove from it, edit any of this text. It's all XML-driven. I no longer have to open up Flash to update my site. Everything is external, really making my site flexible.
Get unlimited access to all courses for just $25/month.Become a member