7 Replies Latest reply on Dec 3, 2013 11:32 AM by kglad

    Cache on Timeline?

    FilipeRS

      Recently I created a function on a swf that basically hides some buttons until the audio playing on that frame is over. When this happen a function is called and the buttons became visible again.

       

      The code is very simple. It's like this:

      var my_sound:Sound = new Sound();

      my_sound.loadSound("audio/som1_1.mp3",true);

       

      my_sound.onLoad = function(sucess:Boolean){

          if( ( _root.temporizador == 1 || _root.temporizador == undefined ) && sucess ) {

              botao_avancar._alpha = 0;

              botao_avancar.enabled = false;

              my_sound.onSoundComplete = doSoundComplete;

          }

      }

       

      function doSoundComplete() {

          botao_avancar._alpha = 100;

          botao_avancar.enabled = true;

      }

       

      My problem is, whenever I change the frame, and the button is in a different place on the screen, it appears on the same position as the last frame, kind of a cache, I guess. Someone know a way to fix this? It's really weird.

       

      I have a .fla sample of this in the link: http://ouromoderno.com.br/flashError/demo.fla
      And I have an online sample, so you can see what happens: -> http://ouromoderno.com.br/flashError/

       

      Appreciate any ideias.

       

      (Sorry for the very bad horrible awful english )

        • 1. Re: Cache on Timeline?
          kglad Adobe Community Professional & MVP

          when your button appears in a new place you have a keyframe containing the button and therefore another button instance.  making a previous button instance not visibiel won't affect the visible property of the new button instance.

           

          to remedy, use a boolean variable to record whether your button is visible or not.  use the boolean in other frames to assign the new instances visible property:

           

          my_sound.onLoad = function(sucess:Boolean){

              if( ( _root.temporizador == 1 || _root.temporizador == undefined ) && sucess ) {

                  botao_avancar._visible=false;

          botao_visible=false;

                  my_sound.onSoundComplete = doSoundComplete;

              }

          }

           

          function doSoundComplete() {

              botao_avancar._visible=true;

          botao_visible=true;

          }

           

          // on your other frames:

           

          whateverbotao._visible=botao_visible;

           

          //p.s. use the _visible property and you don't have enable/disable your button.

          • 2. Re: Cache on Timeline?
            FilipeRS Level 1

            Thanks for the reply. I didnt know about the _visible property, thanks!
            About my doubt, I am thinking on doing something like that:

            I will create an array of booleans and set everything to false in the begining. Everytime I call doSoundComplete it will set that frame to true. In essence, this is what you told me to do right?

            • 3. Re: Cache on Timeline?
              kglad Adobe Community Professional & MVP

              how many buttons do you need to track?

              • 4. Re: Cache on Timeline?
                FilipeRS Level 1

                I work on a company that sells classes made in Flash. The number of frames vary, but in average it is about 50 frames. So 50 buttons per SWF :/

                • 5. Re: Cache on Timeline?
                  kglad Adobe Community Professional & MVP

                  it would be probably be easier to just name your buttons prudently.  for example, btn_0, btn_2, ..., btn_49;

                   

                  you can then use:

                   

                   

                  // to set all visible variables true;

                  for(var i:Number=0;i<50;i++){

                  this["btn_"+i+"_visible"]=true;

                  }

                   

                   

                  // to set all button's _visible properites

                  for(var i:Number=0;i<50;i++){

                  this["btn_"+i]._visible=this["btn_"+i+"_visible];

                  }

                  • 6. Re: Cache on Timeline?
                    FilipeRS Level 1

                    The problem is my company has already more than 900 swf's in use. To instanciate all buttons according to this, would take a lot work. I think i will make a script that rename botao_avancar to botao_avancar+currentFrame, to avoid more problems. Thanks for the tips!

                    • 7. Re: Cache on Timeline?
                      kglad Adobe Community Professional & MVP

                      you're welcome.