9 Replies Latest reply on Sep 20, 2007 1:07 PM by CarrieBey

    Buttons in ActionScript 3 ?!?!?!

    Ricky_Lopes
      hi...

      I'm trying to make a sound controller in actionscript 3. I used to do this nicely in actionscript 2, but know it seems that nothing works as in "the old days"...
      I created a button and tried to add actionscript to it but it doesn't let me :-(

      How can i apply code to a button on flash CS3 to start and stop a specific sound?
        • 1. Buttons in ActionScript 3 ?!?!?!
          Juankpro Level 2
          ActionScript 3.0 was designed for advanced Object-Oriented programmers. Even though this approach is a lot more powerful, it requires a lot of knowledge and re-learning. Like for example that every on() event is not only deprecated in this version but completely removed. So, as the same documentation says. If your project is not a giant monster, there is no need to learn this programming approach, which will take you a considerable time. You can still export as Flash Player 9 to use its improvements but select ActionScript 2.0 as the ActionScript version on the publish settings panel.

          Take into account that the object structure in ActionScript 3.0 was completely redesigned. So every proccess, from a sinple event to movie clip creation has changed radically.
          • 2. Re: Buttons in ActionScript 3 ?!?!?!
            SymTsb Level 2
            give your button an instance name as you would have in AS2.

            In AS3 every bit of AS2 is tied to the Actions panel or it is done with external AS files and packages.

            With that said....

            buttonName.addEventListener( MouseEvent.CLICK, handleClick );

            function handleClick( e:MouseEvent ):void {
            // Do whatever needs to be done with your sound object
            }

            It's a little different from an external class file but overall this is the general practice.
            • 3. Re: Buttons in ActionScript 3 ?!?!?!
              Ricky_Lopes Level 1
              hi juankpro and SymTsb!
              thanx for the replies ;-)

              I'm redesigning my site and i want to learn a bit more of actionscript, thats why i want to do it in actionscript 3.

              must i insert this code in every actions layer were i need to use the button?

              buttonName.addEventListener( MouseEvent.CLICK, handleClick );
              function handleClick( e:MouseEvent ):void {
              // Do whatever needs to be done with your sound object
              }
              • 4. Re: Buttons in ActionScript 3 ?!?!?!
                SymTsb Level 2
                No. That's the beauty of AS3. You define the button handler for the button and it exists in the AVM (Actionscript Virtual Machine) as long as the display object it references exists.
                • 5. Re: Buttons in ActionScript 3 ?!?!?!
                  Ricky_Lopes Level 1
                  humm...cool :-D

                  i used stopAllSounds(); for my stop button, but it seems that stopAllSounds has been deprecated :-S
                  is there a simpler command to do the same thing?
                  • 6. Re: Buttons in ActionScript 3 ?!?!?!
                    SymTsb Level 2
                    Read the Sound Class page in AS3 help. The sound class now only provides a means for starting a sound. You must add a SoundChannel object to your sound class to actually stop it. I'm not sure what the sense was in this but it is none-the-less how it is handled now in AS3
                    • 7. Re: Buttons in ActionScript 3 ?!?!?!
                      CarrieBey
                      I have a similar problem. I need to create a CD with a menu and several 1-2 min video clips (with audio that needs to stay in sync). I also need a "return to menu" button under each video. When I use ActionScript 2.0 and attempt to test with .FLV files I get this error:
                      WARNING: The component 'fl.video.FLVPlayback' requires ActionScript 3.0.
                      When I use ActionScript 3.0 and attempt to test I get this error:
                      WARNING: Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored.

                      Any suggestions?
                      Thanks,
                      Carrie
                      • 8. Re: Buttons in ActionScript 3 ?!?!?!
                        SymTsb Level 2
                        Make sure that your FLA is a Flash (Actionscript 2) document. Also make sure you are calling on the proper package for an AS2 document. From the looks of the errors, your FLA is an AS3 document but I can't be positive without looking at the actual FLA
                        • 9. Re: Buttons in ActionScript 3 ?!?!?!
                          CarrieBey Level 1
                          Sorry, I'm not sure that I understand your response. One of the error message occurred when I saved as an AS2 project and one was when I saved as an AS3 project. Also, I'm not sure what you mean when you say "calling on the right package"

                          Thanks,
                          Carrie