5 Replies Latest reply on Mar 9, 2012 2:14 PM by katie365

    Help.... close box....button...thing...???

    katie365

      Hi,

       

      I have been creating a calendar with popup boxes on certain events, the boxes contain information, pictures etc... anyway, but now I want to add an X to the box so that you can close the box by clicking on it.

       

      I have been researching this for hours and I cannot do it, its probably really easy and im being stupid but do you know the code I could use? Please?

      Here's a screenshot of where the X is and the black box I would like to close after clicking on the X. The X is red by the way!

       

      Picture 2.png

       

      Thanks, I hope you can help!

        • 1. Re: Help.... close box....button...thing...???
          sinious Most Valuable Participant

          I see you're in a MovieClip called togglesausagefestival. Are you making separate movieclips for all these events yourself?

           

          I also see an animation layer. I assume you want to play that animation which probably fades the box out and then get rid of it?

           

          I would add an event listener to the X to play() the timeline:

           

          xButton.addEventListener(MouseEvent.CLICK, playClose); // add the listener but obviously change 'xButton' to whatever instance name you named it

           

          function playClose(e:MouseEvent):void

          {

            play(); // play the playhead

          }

           

          Now on the last frame of the animation in the code layer:

           

          MovieClip(this.parent).removeChild(this);

           

          The general idea here is to get the playhead to play after the X is clicked playing the closing animation, then on the last frame the clip is telling its parent to remove itself.

          • 2. Re: Help.... close box....button...thing...???
            katie365 Level 1

            Hi,

             

            Thanks, it sort of worked but when I click on it on the X it closes but if I click back on the button to open the pop up window again, it doesn't pop up and I need it to...am I doing something wrong or is there another code for that? Here I what I have done:

            Picture 2.png

            Picture 3.png

            • 4. Re: Help.... close box....button...thing...???
              sinious Most Valuable Participant

              How did you load the togglesausagefestival clip in the first place? You'll need to use that code to place something else in there.

               

              If you right-click on a clip in your library and check the box to export for actionscript it will give that movieclip a way to be accessed via code. On your main timeline (not inside any clips) you could put a function that will load something.

               

              e.g. frame 1 of the main timeline

               

              function loadDefaultContent():void

              {

                 var defaultContent:MovieClip = new togglesausagefestival(); // whatever you name your "actionscript linkage" should replace togglesausagefestival

                 addChild(defaultContent); // add it to be displayed

                 defaultContent.x = 100; // set x position

                 defaultContent.y = 200; // set y position

              }

               

              If this is on the main timeline then another timeline script can run that function which will load whatever you tell it. You can make 20 functions, each loading something different, or you can use one function and pass a value to it to tell it what to load (million ways to skin a cat).

               

              Then on the last frame of MovieClip togglesausagefestival in the frame script you'd do:

               

              MovieClip(this.parent).loadDefaultContent();

              MovieClip(this.parent).removeChild(this);

               

              Not exactly the best coding practice but should be fairly understandable to you.

              • 5. Re: Help.... close box....button...thing...???
                katie365 Level 1

                Well here's a screenshot of my code for the box... I am a beginner at this so I dont reaaluy know exactly what your talikgn about...I kinda get it but it be easier to give you the files? just so you can check it out quickly and see where I need to put code? Only if your willing to of course but if not then we can do this by screenshots.

                 

                Picture 5.png