8 Replies Latest reply on Jan 21, 2010 2:17 PM by TerraAustralis

    Can AS attach image fade to Toggle button?

    TerraAustralis Level 1

      I have completed my first Flash 8 movie which has an invisible button the size of the image which Stop/starts the movie with AS toggle script below.

       

      click_btn.onRelease=function(){

      if(!this.toggle){

      chameleon.stop();

      } else {

      chameleon.play();

      }

      this.toggle=!this.toggle;

      }

       

      Can this script be modified so that the movie fades to alpha zero a short time after the stop action, and the re-appears to play instantly when the play action is triggered? If so can anyone help with a script suggestion please.

        • 1. Re: Can AS attach image fade to Toggle button?
          Ned Murphy Adobe Community Professional & MVP

          Look into using the Tween class for the _alpha fade that accompanies the stop();  To have it reappear instantly for the play(); just set its _alpha value to 100 before the play() command.

          1 person found this helpful
          • 2. Re: Can AS attach image fade to Toggle button?
            TerraAustralis Level 1

            Dear Ned,

            Thank you for your suggestion. I am a rank beginner and do not have enough understanding of AS to follow your suggestion. kglad kindly provided the AS cited in reply to an earlier request.

             

            I have looked into AS 2.0 movie clip classes where I can see -alpha. However I cannot find Tween classes and also need to express the -alpha fade time of 10 seconds.

             

            I do not mind doing the research and working at the syntax if you could help me with more specific reference about Tween classes and the expression of time.

             

            Best Wishes,

            • 3. Re: Can AS attach image fade to Toggle button?
              Ned Murphy Adobe Community Professional & MVP

              When you use the Tween class it includes a provision for specifying the duration of the transition.  For information on each method and property of the Tween class, look under ActionScript 2.0 Components Language Reference in the Flash help documentation.  The Flash help documents are a primary resource for information on anything to do with actionscript and using Flash.  You can also try searching Google for "AS2 Tween".  Generally Google searches produce excellent results, isolating both the information you might find in the Flash help documents and articles and solutions posted throughout the web.

              1 person found this helpful
              • 4. Re: Can AS attach image fade to Toggle button?
                TerraAustralis Level 1

                Thanks again Ned,

                A freind of my son worked on this question and following your comments came up with the following code but we cannot make it work.

                 

                **Error** Scene=Scene 1, layer=Code, frame=1:Line 1: Syntax error.

                     import mx.transitions.Tween;

                 

                **Error** Scene=Scene 1, layer=Code, frame=1:Line 2: Syntax error.

                     import mx.transitions.easing.*;

                 

                Total ActionScript Errors: 2 Reported Errors: 2

                 

                Can anyone help fix the code please?

                 

                 

                import mx.transitions.Tween;

                import mx.transitions.easing.*;

                var secNum:Number = 2;

                var aTween:Tween;

                click_btn.onRelease = function() {

                if (!this.toggle) {

                chameleon.stop();

                aTween = new Tween(chameleon, "_alpha", Quad.easeInOut, 100, 0, secNum, true);

                aTween.onMotionFinished = function() {

                delete aTween;

                chameleon._visible = false;

                };

                } else {

                aTween.stop();

                chameleon._visible = true;

                chameleon._alpha = 100;

                chameleon.play()

                }

                this.toggle = !this.toggle;

                };

                • 5. Re: Can AS attach image fade to Toggle button?
                  Ned Murphy Adobe Community Professional & MVP

                  The code appears to be fine (to me).  Are you sure your Publish Settings are for AS2?

                  • 6. Re: Can AS attach image fade to Toggle button?
                    TerraAustralis Level 1

                    You are quite right Ned, the Publish settings were for Action script 1.0!

                     

                    The code ran fine once that was changed.

                     

                    One last request please. The movie fades to white. I want it to fade to black. How should I express that in code?

                    • 7. Re: Can AS attach image fade to Toggle button?
                      Ned Murphy Adobe Community Professional & MVP

                      When you are fading something, you're making it invisible, so I don't see how it fades to white.  It may just be a case where you need to make something's background color black, though I don't know what that something will be.

                      • 8. Re: Can AS attach image fade to Toggle button?
                        TerraAustralis Level 1

                        Of course Ned, I am so focused on AS that I am forgetting the basics. I changed the stage colour to black and all works well.

                         

                        Now I shall sit glued to the clip watching it change for two days, fascinated with the ability of AS! Really this exercise has been a great incentive and has provided me with a great incentive for serious study. I followed your search advice and found an excellent tutorial at about tween classes which offers further understanding of AS (http://www.kirupa.com/developer/actionscript/tween.htm).

                         

                        Thanks for all your help Ned. It is much appreciated.