In another layer I have the buttons, but they do not appear in every frame.
I noticed that I need to use the “uhc” in the same frame number of the buttons.
Is there a way to fix this?
This way I can`t specify a function to all the buttons in just one frame!
Like this:
Yes, you are correct, you have to use uhc with each frame that contains your buttons in your .fla.
The reason is because breaking up an object’s existence on the timeline into multiple, discontinuous frames effectively creates multiple instances of the object. So your code to control a button works, but it only works for that one instance, not all the other instances. That is why you have to put that new code on each frame that contains a new instance of the button.
You could pursue some other methods to work around this, such as making the buttons invisible (btn01._visible = false;) on those frames where you don’t want the buttons. That might keep a continuous instance of the buttons across the entire timeline so that one function could control that instance across the entire timeline.
Just curious: what happens when all the instances have the same name? what does it do?
Good explanation aurelius
That really made my mind clear!
I just thought about a new method and I`ll try it now. And if I create one layer with continuous frames and make one single button invisible? That would make things easier!!
Sorry but I didnt get your questions! What happens to what?
I was just curious what happened if you gave every button(s) on the timeline to the same instance name (i.e. if you gave every instance of btn01 an instance name of “btn01”) and then played the clip. It sounds like that’s what you did and I was curious what happened when you tested the movie.
I realized the answer since my last post. Each instance is not initialized on the stage until the playhead gets to the keyframe which holds that instance. So a uhc = false command on the first keyframe won’t apply to the instance in the tenth keyframe because that tenth instance hasn’t been initialized yet.
I.e. you can’t use code that controls an instance before that instance is initialized.
I created another layer with 15 continuous frames and put one btn01 instance.
The uhc was ok only in the first instance of the btn01.
In the other frames that contain 2 instances, one invisible and the other visible, the uhc function in the instance that is on the continuous layer.
Yehh, u cant break up the frames!
Could you think about something?
I think I`ll put the code in each btn and not in one single function!!!
Or you could just keep one instance of the button and make it invisible on the frames where you want it to be disabled and invisible.
Something like this. Place the button on the first frame with this code:
this.btn01.useHandCursor = false;
Then on frame 5, when you don’t want the button to be visible, leave the button on the stage, but put this code on frame 5:
this.btn01._visible = false;
Then when you want the button back again, e.g. on frame 6, put this code on frame 6:
this.btn01._visible = true;
and continue this process for however you need it. Since the one instance of the button is always there, your useHandCursor function will apply to the button throughout the timeline.
I noticed that when there are more than one copy of the instance in the same frame, the uhc and the function call only works in the first instance created.
(In this case I`m calling a function on the main stage to show a hovercaption for the same icon, that repeats several times, in discontinuous frames in the same layer.)
In some frames I have 4 instances of the btn01.
Please, if you think about something, let me know!!
yeh! it`s a symbol.
2 to 5 times in the same frame.
Is this wrong? Whats the best way to have a symple btn, multiple times in the same frame, accessing the same function?!
Ah, I see. We’re just getting confused over terminology. :)Symbols in the library are called “symbols”. The name you give to that symbol when you first create the symbol (or when you right click on the symbol and select ‘properties’) is the “symbol name”. When you drag a copy of the symbol onto the stage, it then becomes an “instance” of the symbol. When you give the instance a name in the Properties Inspector, that is the “instance name”. Is that what we’re getting confused about?
You can have as many instances of a symbol on the same frame as you want, that’s not a problem. The only thing is that each instance has to have its own instance name. You use the instance name rather than the symbol name to control objects with actionscript.
If you drag a copy of “Btn01” on the stage and give it an instance name of “myButton1_mc”, then you can use actionscript to control it like this:
myButton1_mc.useHandCursor = false;
myButton1_mc._visible = false;
myButton1_mc.onPress = function() {
trace("button 1 has been clicked");
} // end myButton1_mc.onPress()
// etc.
You can then drag another copy of “Btn01” on the stage and give it a different instance name (how about “myButton2_mc”) and use actionscript to control that instance:
myButton2_mc.useHandCursor = false;
myButton2_mc._visible = false;
myButton2_mc.onPress = function() {
trace("button 2 has been clicked");
} // end myButton2_mc.onPress()
// etc.
I hope I’m making sense here.
So it sounds like you have “Btn01” as a symbol in your library and you need to give each instance a unique instance name so your actionscript can control each instance separately.
As for what we were saying earlier, you only need one instance on the stage in frame one, name it, then use actionscript on the proper frames to set that instance to _visible = false; when you don’t want it visible on the stage.