18 Replies Latest reply on May 26, 2015 6:28 PM by Arcgisfan

    Need assistance with button scripting!

    Arcgisfan

      I believe my question to be an easy one but I am a noob at scripting. I have buttons all over my project and what I want is when a user clicks on one of the buttons for the rollover to pop up and stay up, then if the user clicks outside of the area the rollover to go away.

       

      Can anyone tell me the code for this? Or a way to find out the code? Thanks a bunch!

        • 1. Re: Need assistance with button scripting!
          robdillon Most Valuable Participant

          What is the rollover? Is this part of the button itself, as in the selected state of the button? Or is this something in addition to the button itself? If it is separate, does only one show at a time? Where is the user clicking that is outside the area? Is it not on that same button? Is it on another button? Can you clarify or show an example of what you have in mind?

          • 2. Re: Need assistance with button scripting!
            Arcgisfan Level 1

            Basically, I want the little rollover on this image http://i.imgur.com/7Jvz5rH.png to pop up and stay up when the icons (poke'balls) on the map is clicked. I do not mean the map to pop up but the little box to the right of the map to pop up when the buttons (Poke'ball icons) on the map are clicked.

             

            What I desire to know is what is the code that allows me to do that. via scripting. All of the icons and the rollover windows have instance names.

             

            Here is my code.

             

            import flash.events.MouseEvent;

             

            stop();

             

            Amelia.addEventListener(MouseEvent.CLICK, Amelia_Infoclick);

            function Amelia(event:MouseEvent):void

            {

                    I need to know what goes here. I know it is the instance name of the window but what is the code.

            }

             

             

            Thanks!

            • 3. Re: Need assistance with button scripting!
              robdillon Most Valuable Participant

              OK. There are three different ways that you can make something "appear" on the stage.

              1. You can change the "visible" property.

              2. You can change the "alpha" property.

              3. You can change the "x" and/or "y" property.

               

              The visible property is a go/no go property, and so the movieClip will be visible or not.

              The alpha property allows you to fade the movieClip in or out, so you can have a little more drama.

              The x and y properties allow you to move the movieClip into position and back out.

              You can combine the alpha and the position change if you like.

               

              So, the simplest version might look like this:

              --------------

              import flash.events.MouseEvent;

               

              stop();

              // set the initial visible property to false to hide the movieClip...

              moreInfoClip.visible = false;

              Amelia.addEventListener(MouseEvent.CLICK, Amelia_Infoclick);

              function Amelia_Infoclick(event:MouseEvent):void

              {

                   // toggle the visible property when the button is clicked...

                   if(moreInfoClip.visible == false) {

                          moreInfoClip.visible = true;

                   } else {

                        moreInfoClip = false;

                   }

              }

              ----------------

               

              Does that give you a good start?

              1 person found this helpful
              • 4. Re: Need assistance with button scripting!
                Arcgisfan Level 1

                Mmm sort of. But, now I'm getting loads of errors. http://i.imgur.com/ilmgYGI.png It keeps saying I have an undefined property, but the instance name of the popup window is called Amelia_Info and I checked the spelling 3x. Also I do not know where to change the the alpha property to fade the movieClip in or out. That drama effect would be awesome! Do I have to do that with code too?

                • 5. Re: Need assistance with button scripting!
                  Ned Murphy Adobe Community Professional & MVP

                  Does the error appear after you click "Amelia"  or as soon as you try to run the program?  If it occurs when you click then could you be in a different frame at the time where Amelia_Info does not exist?

                   

                  Side note:  Line 30 is likely wrong the way you wrote it.  Doesn't it need a ".visible" in there.

                  1 person found this helpful
                  • 6. Re: Need assistance with button scripting!
                    robdillon Most Valuable Participant

                    Sorry, that was my fault. That last line should say:

                    moreInfoClip.visible = false;

                    • 7. Re: Need assistance with button scripting!
                      Arcgisfan Level 1

                      The error happens when I run the program.

                       

                      Now I am getting all of these errors.

                       

                       

                      Here is the code.

                       

                      import flash.events.MouseEvent;

                       

                       

                       

                      stop();

                       

                      // set the initial visible property to false to hide the movieClip...

                       

                      Amelia_Info.visible = false;

                       

                      Amelia.addEventListener(MouseEvent.CLICK, Amelia_Infoclick);

                       

                      function Ameliaclick(event:MouseEvent):void

                       

                      {

                       

                           // toggle the visible property when the button is clicked...

                       

                           if(Amelia_Info.visible == false)

                          {

                       

                                  Amelia_Info.visible = true;

                       

                           }

                          

                           else

                          

                           {

                       

                                Amelia_Info.visible = false;

                       

                          }

                       

                      }

                      • 8. Re: Need assistance with button scripting!
                        Ned Murphy Adobe Community Professional & MVP

                        Based on the error messages in the last image you showed I have to conclude that you did not name any object Amelia_Info.  Show the object selected on the stage along with the name assigned in the properties panel's Instance Name field.  Include the timeline as well so that the frame is indicated.

                         

                        Another thing I notice about the errors is that they are all pointing to frame 2... but the image you showed earlier appears to have no content in frame 2.  If you have the code in frame 2 but the object is not there then as far as the code sees it the object doesn't exist.

                        1 person found this helpful
                        • 9. Re: Need assistance with button scripting!
                          Arcgisfan Level 1

                          The thing is there is an object named Amelia_Info. See http://i.imgur.com/4AhsIeH.png So I do not know why it says it is not defined. It is a movie clip if that makes a difference.

                          • 10. Re: Need assistance with button scripting!
                            Colin Holgate MVP & Adobe Community Professional

                            You seem to have the info movieclip in the rollover frame of a button, presumably the button that is to toggle the visibility. The movieclip should be at the same level as the button, not inside it.

                            • 11. Re: Need assistance with button scripting!
                              Arcgisfan Level 1

                              Your suggestion worked! But now I have to do this for like 20+ more locations. And it's in the way when I want to begin adding text in the box. How do I fix that?

                              • 12. Re: Need assistance with button scripting!
                                Arcgisfan Level 1

                                "Your suggestion worked! But now I have to do this for like 20+ more locations. And it's in the way when I want to begin adding text in the box. How do I fix that?" Never mind about this question. I figured it out by clicking the invisibility box. But now I have two more questions, (LOL) I have text in the box but when I click the invisibility box only the image goes and not the text. Is there a way to fuse or link the text to the image so when I click the visibility box the whole thing goes away and not just the image?

                                 

                                With the code that I have now.

                                 

                                import flash.events.MouseEvent;

                                // set the initial visible property to false to hide the movieClip...

                                Amelia_Info.visible = false;

                                Amelia.addEventListener(MouseEvent.CLICK, Amelia_InfoClick);

                                function Amelia_InfoClick(event:MouseEvent):void

                                {

                                     // toggle the visible property when the button is clicked...

                                     if(Amelia_Info.visible == false)

                                    {

                                            Amelia_Info.visible = true;

                                     }

                                     else

                                     {

                                          Amelia_Info.visible = false;

                                      }

                                }

                                 

                                Will I be able to just change the names within it for the rest of the 20+ locations I have without getting an error?

                                • 13. Re: Need assistance with button scripting!
                                  Colin Holgate MVP & Adobe Community Professional

                                  You can have the 20 different movie clips with the same instance name, assuming they're on different frames. You can also toggle the visibility without an if statement. Suppose all of your info boxes are named "info_box", your toggle function can be:

                                   

                                  function InfoClick(event:MouseEvent):void {

                                      info_box.visible = !info_box.visible;

                                  }

                                  • 14. Re: Need assistance with button scripting!
                                    Arcgisfan Level 1

                                    What about the text? It won't vanish with the image box.

                                    • 15. Re: Need assistance with button scripting!
                                      Colin Holgate MVP & Adobe Community Professional

                                      The text should be inside the movieclip.

                                      • 16. Re: Need assistance with button scripting!
                                        Arcgisfan Level 1

                                        How do I get it inside of the movieclip? The text that I have is static with a hyperlink in it as well. Sorry, I'm not good with Flash. >_<

                                        • 17. Re: Need assistance with button scripting!
                                          Colin Holgate MVP & Adobe Community Professional

                                          Select the textfield and copy it. Double-click into the movieclip and do a paste. You should still see a ghosted image of the original textfield, which you can use to get the textfield aback into the same place it was. You can use the text links along the top of the Flash stage window to go back up one level, or just double-click on a spare part of the stage. Once you're back at that level you can delete the original textfield.

                                          • 18. Re: Need assistance with button scripting!
                                            Arcgisfan Level 1

                                            The code that you suggested earlier

                                             

                                            function AmeliaClick(event:MouseEvent):void

                                             

                                            {

                                                info_box.visible = !info_box.visible;

                                            }

                                             

                                            I tried using it and well, it is not making the box reappear when it the icon is being clicked.

                                             

                                            Amelia is the instance name of the icon

                                             

                                            and info_box is now the new instance name of the box that I want to pop up.