1 Reply Latest reply on Jun 17, 2008 8:44 PM by Noelbaland

    Dynamic Picture

      I had a similar question with text earlier and now I'm trying to do it with pictures. You people were so nice to help out...hopefully you can do it again!

      I'm looking for a script that'll load a picture when you click on a particular button. I'd also like a text caption to come up below the picture. When you click another button, a whole new picture and caption appears and so forth. Finally, I'd like there to be a default picture in the image container when the page first loads.

      I think I know how to make dynamic text appear (i.e. the caption) although I'm not sure how to do the picture part and how to put it all together into a nice little script.

      Thank you again in advance.
        • 1. Dynamic Picture
          Noelbaland Level 1
          Hello there,

          This is an "ol skool" method and was one of the first scripts I learnt back when I had Flash MX 2004. It is really basic but still one of my favorites.

          Anyways, I'll assume that you have a movieclip on stage that will load in your images. Make sure it has a top left registration point. If it doesn't then go into the movieclip and set it's X and Y to 0 in the Properties panel. We'll call this movieclip "holder". Also you should have a dynamic textbox and some buttons. The script has instance names "caption" for the textbox and "pic1" and "pic2" for the buttons.

          Open a text editor (Notepad, Textmate) and paste this into it

          caption1=This is the caption for Picture 1&pic1=pic1.jpg&caption2=This is the caption for picture 2&pic2=pic2.jpg

          Save it as info.txt in the same folder as the swf file.

          Back in Flash create a new layer called "actions" and copy and paste the script at the bottom. Make sure have a folder called "images" with your pictures in it. Test your movie.
          If all went well you should see your first image and caption and the button should load their captions/pictures.

          Basically all we've done is put variables in an external text file and loaded them into Flash. You could have done the same within Flash but this way is more flexible as you only need to edit the text file if you want to change the caption and picture. Flash reads the variables in as a URL encoded string. To add more variables to the text you must use the ampersand(&) character to seperate variables and their values. e.g varA=valueA&varB=valueB

          There is still work to be done on this script like checking if the file has loaded and checking for errors but thats pretty much the gist of it.

          Hope it helps!