9 Replies Latest reply on May 3, 2009 10:22 AM by kglad

    More than one function in a button?

    missklingklang

      Hi, I have created a button that moves around automaticly, and made it so that you also can steere the button when holding the button in och dragging it.

       

      What I want is:

      1. Having 4 buttons that move arround automaticly.

      2. Have a text that will turn up dragging the mouse over the buttons

      4. With a mouseclick manage to stop the automatic movement

      3. Have the butons linket to each URL site which will be reached with a double click.

       

      Do anyone know how I´ll manage this?Where do I put the codes? In ActionScipt over all the buttons or within each button?

      Please help

       

      Thanks

       

       

       

       

      The automaticly movement is already done.

      All the buttons is made into MovieClips, and withon them the buttons are "Buttons". Within the buttons are this code:

       

      acceleration = 30
      newpos = function () {
          ranx = Math.round((Math.random ()*755));
          rany = Math.round ((Math.random ()*755));
      }
      newpos();
      this.onEnterFrame = function() {
          this._y += ((rany-this._y)/acceleration);
          this._x += ((ranx-this._x)/acceleration);
         
          if (Math.round(this._x) == ranx || Math.round(this._y) == rany) {
              newpos();
          }
      };

       

       

      Free draggning arround.

      This code is for all the objects in the outmost layer.

       

      squarepos_so = SharedObject.getLocal("positions");
      xx.text = boll1._x = squarepos_so.data.x;
      yy.text = boll1._y = squarepos_so.data.y;

       

      boll1.onPress = function () {
      boll1.startDrag(false)
          }
      boll1.onRelease = boll1.onReleaseOutside = function(){
         boll1.stopDrag();
       
          xx.text = squarepos_so.data.x = boll1._x;
          yy.text = squarepos_so.data.y = boll1._y;
         squarepos_so.flush();
      }

        • 1. Re: More than one function in a button?
          kglad Adobe Community Professional & MVP

          1.  your movement code would go on each button's timeline.

           

          2.  add the to your onPress function

           

          4.  you'll need to use a timer to decide when a mouse release over a button is the end of a button drag or it's a click

           

          3.  you'll need to use a timer to detect a double click and then use getURL() to open another html page.

          1 person found this helpful
          • 2. Re: More than one function in a button?
            missklingklang Level 1

            Hi, thanks for your answer.

             

            1. Does it mean that I should apply the movement in the frames icg each button and not as a actionscript? I have a code that makes the buttons to go randomly. But since the buttons have the same source (they are all copied from the same sourcebutton in the library) they´re all effected.

             

            2. Do you mean a onPress code in each button, or do you mean just to put the effect in the "Up, Over, Down, Hit" timeline?

             

            I´m new to this so I don´t know if it´s more usual to use the frames in the timeline, or to use actionscript in just the first frame of the timeline.

             

            And how does it work with the so called "children" and "parents". I don´t get it.

            I make a button as a MovieClip - because I want it to me movable. Then I make a button of the button within the MovieClip because I want the button to be a link to another website.

             

            Or should I first make the button to a button and then into a MovieClip. It´s confusing

             

             

            I´m really thankful for all the anwers I get

            • 3. Re: More than one function in a button?
              kglad Adobe Community Professional & MVP

              1.  add the movement script to the first frame of the timeline of each movieclip button.

               

              2.  add the text-revealing code to the onPress actionscript function for each movieclip button that you want to reveal text

               

              an object that's on the timeline of a movieclip is a child of the movieclip and the movieclip is the parent of the object.  a movieclip can have many children.  each child can have only one parent.

               

              don't use buttons.

               

              each movieclip can be made to function like a button simply by using actionscript:

               

              mc.onRelease=function(){

              //

              }

              1 person found this helpful
              • 4. Re: More than one function in a button?
                missklingklang Level 1

                So should I simply put this code in one the first frame of each button?

                 

                 

                acceleration = 30
                newpos = function () {
                    ranx = Math.round((Math.random ()*755));
                    rany = Math.round ((Math.random ()*755));
                }
                newpos();
                this.onEnterFrame = function() {
                    this._y += ((rany-this._y)/acceleration);
                    this._x += ((ranx-this._x)/acceleration);
                   
                    if (Math.round(this._x) == ranx || Math.round(this._y) == rany) {
                        newpos();
                    }
                };

                • 5. Re: More than one function in a button?
                  kglad Adobe Community Professional & MVP

                  yes, each movieclip button

                  • 6. Re: More than one function in a button?an
                    missklingklang Level 1

                    thank you very much, I think I got it!

                     

                    Now the only problem I have left is to have a text to show up at "MouseOver" of each button.

                     

                    Do you know how it´s done. I know that you can do it within a button in the "UPP, OVER, DOWN and HIT timeline.

                    But that doesn´t work because then all the other effects disappear

                     

                    Am I going to put a code like: on each button (or within each button) or over a ActionScript-frame for all the buttons

                     

                    on (MouseOver) {

                               button1. something(I dont know)?

                    }

                     

                    on (MouseOver) {

                               button2. something(I dont know)?

                    }

                     

                     

                    etc..

                    • 7. Re: More than one function in a button?an
                      kglad Adobe Community Professional & MVP

                      on your movieclip's timeline add a dynamic textfield (say tf).  you can then use:

                       

                      btn.onRollOver=function(){

                      this.tf.text=this._name;

                      }

                      btn.onRollOut=function(){

                      this.tf.text="";

                      }

                      • 8. Re: More than one function in a button?an
                        missklingklang Level 1

                        But in which timeline will i put the text. Or will I just have it in the library. Because if i put it in the timeline the text will be shown all the time

                         

                        thanks again

                        • 9. Re: More than one function in a button?an
                          kglad Adobe Community Professional & MVP

                          the text is dynamic.  it's assigned when you rollover your button and it's reassigned to an empty string when you rollout.