2 Replies Latest reply on Aug 18, 2009 10:17 PM by Rothrock

    If and Else Statements? Help!!

    angryannoyance

      I'm making a dress up game in Adobe Flash 8 (AS2) and I'm trying to Show and Hide multiple Movie Clips on release of a button to make sort of a menu like this one :


      http://charfade.deviantart.com/art/Dress-Up-Nala-Game-107105062

       


      Its probably if/else statements but i dont know how to code them in ActionScript 2 so it would very-much help if you had an answer

        • 1. Re: If and Else Statements? Help!!
          kglad Adobe Community Professional & MVP

          you can use the _visible property of movieclips to show (mc._visible=true) and hide (mc._visible=false) a movieclip mc.

          • 2. Re: If and Else Statements? Help!!
            Rothrock Level 5

            Probably not if/else statements. They are great when you have a couple of choices, but as things get bigger the possible combinations explode and the code gets far to complex. Not that it can't be done, but it is messy, prone to error, and likely to become a nightmare. In this case I would probably recommend the clever use of MovieClip parents and arrays.

             

            So, I'm going to assume a fairly static design -- meaning that you have, say 10 different shirts, and you aren't going to be changing those 10 or adding new ones all the time. Even if this isn't the case it is a good starting point for making what you will need.

             

            So make a new movie clip called, "Shirts." In that clip you can arrange your artwork (which most likely will also be movieclips).

             

            Do the same things for one called, "Shoes," another called "Pants" and so on.

             

            Of course you will want to design what these clips look like, they should probably be the same shape and size and maybe have a background or not. I don't know. Doesn't matter.

             

            Put each of those clips on your stage. Give them instance names like "shirts," "shoes," and "pants." (I name my clips in my library with capital letters and my instances with lower case. It makes it easy to tell what is what. Just an idea....) You might want to put each one on a layer and stack them all up. The layers make it easier to hide/show a layer an manipulate stuff.

             

            Now add some code to a frame:

             

            var home:MovieClip=this;

            var theItems:Array=["shirts","shoes","pants"]

             

            function hideItems(){

               for(var i=0;i<theItems;i++){

                   var curItem:MovieClip=home[theItems[i]];

                   curItem._visible=false;

                }

            }

             

            Then whenever you need to show a specific group of items you can first call the hideItems() function to hide all of them. And then unhide the one that you do want to show.

             

            Or perhaps an even easier way would be to still make clips for each type of thing. Then make a new movieclip of all the items, but with each item on a separate frame. You could then send that movieclip to that specific frame. Or you could space them out, say put 10 frame or so between each keyframe and each keyframe has one of the different movieclips. You could then add frame labels and have that clip jumpt to which ever type of item it needed to show.

             

            Both of these are pretty easy ways to do it and they don't get that much more complex if you suddenly need to add a "pocket square" category. But try doing that with if/else...yikes!

            1 person found this helpful