Copy link to clipboard
Copied
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 )
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
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
how many buttons do you need to track?
Copy link to clipboard
Copied
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 😕
Copy link to clipboard
Copied
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];
}
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now