Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Cache on Timeline?

Guest
Dec 03, 2013 Dec 03, 2013

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 )

TOPICS
ActionScript
721
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 03, 2013 Dec 03, 2013

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 == undefin

...
Translate
Community Expert ,
Dec 03, 2013 Dec 03, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 03, 2013 Dec 03, 2013

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2013 Dec 03, 2013

how many buttons do you need to track?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 03, 2013 Dec 03, 2013

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 😕

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2013 Dec 03, 2013

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];

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 03, 2013 Dec 03, 2013

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2013 Dec 03, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines