6 Replies Latest reply on Aug 25, 2011 2:20 AM by Robbing

    Basic problems with Buttons load

    Robbing

      Hay there

       

      I have just started programming AS 2.0 today, but have much experience from Java, C# and a lot of other programming languages.

       

      I just want to know if there is a "attachButton" equviance to _root.attachMovie(...)?

       

      If I need to use _root.attachMovie what is the equviance to onEnterFrame() in a SimpleButton, because this does not work:

       

      class OwnedTile extends SimpleButton {
         
          function onEnterFrame()
          {
              trace("42");
          }
             
      }

       

      It never prints anything in the output even if the Buttons is created (shoved up in the scene)

        • 1. Re: Basic problems with Buttons load
          kglad Adobe Community Professional & MVP

          you can use attachMovie() to add a button to a movieclip:

           

          this.attachMovie("btnID","btn",whatever);

           

          you can't dynamically add anything to a button and there are even significant limitations adding anything to a button in the authoring environment.

          1 person found this helpful
          • 2. Re: Basic problems with Buttons load
            Robbing Level 1

            Thanks, that explains why I where able to se the figures of the buttons.

             

            But when I am in the button is there then a function that gets called every frame like onEnterFrame in a movie clip. Because the code under this text does not send anything to output, even If I can se that the buttons have been created correctly.

             

            class OwnedTile extends SimpleButton {
                   
                    function onEnterFrame()
                    {
                        trace("42");
                    }
                       
                }

             

            Or is this one of the limitiations?

             

            In fact I only need it to do stuff when It get manipulated by the mouse (like on(press)), so if it is not a check every frame then how do I do that?

             

            regards

            • 3. Re: Basic problems with Buttons load
              kglad Adobe Community Professional & MVP

              there's no onEnterFrame method for buttons.

               

              and, you shouldn't use an onEnterFrame even for movieclips if you just need to detect mouseover, mouseout, mousedown,mouseup,mousemove.  there are more efficient methods to detect all those events.  eg, in your OwnedTile class:

               

              this.onPress=function(){

              trace(42);

              }

              • 4. Re: Basic problems with Buttons load
                Robbing Level 1

                That Code does not work nor does this one I saw another place:

                 

                class OwnedTile extends SimpleButton {       
                       
                    on(press){

                 

                        trace(42);

                 

                    }           
                }

                 

                Nor does it work if I put it into the construktor for the class.

                • 5. Re: Basic problems with Buttons load
                  kglad Adobe Community Professional & MVP

                  the code i suggested is the correct syntax.

                   

                  however, the SimpleButton class in as2 is a component so you can't extend it.   also, you can't extend the Button class in as2.  so, use a movieclip.

                  1 person found this helpful
                  • 6. Re: Basic problems with Buttons load
                    Robbing Level 1

                    I ported my projekt to AC 3.0, because it was not that big yet, and the code that made everything work was:

                     

                    package  {
                       
                        import flash.display.MovieClip;
                        import flash.events.MouseEvent;
                       
                        public class FreeTile extends MovieClip {
                           
                            public function FreeTile() {
                                this.addEventListener(MouseEvent.CLICK, myButtonAction);
                            }
                           
                            function myButtonAction(eventObject:MouseEvent) {
                                trace("you clicked on the button ");  
                            }
                        }
                       
                    }

                     

                    But thanks for the help