@kaitie_o_bryan is correct.
The way screens are implemented - they are html <div>
tags with all elements on the screen embedded within them. When you switch screens the entire <div>
of non-active screens becomes hidden and all descendants embedded within it inherit that hidden-ness as well.
The “fancy” way to get behavior like this is, as Kaitie suggests, to just use one screen. You can “fake” having multiple screens by simply showing/hiding the right elements at the right time. I have done this before, but using more sophisticated techniques than are probably available to your students if they are lesson 5.5.
I have a clever way to cheat though - you can take advantage of the fact that if you show a button on a hidden screen it stays hidden. So, if for example, you want the button on 4 different screens, just create 4 different buttons, one on each screen. Whenever you want to show one, just show them all! Make a function that shows/hides these buttons:
function showAllSaveBtns(){
showElement('saveBtn1');
showElement('saveBtn2');
showElement('saveBtn3');
showElement('saveBtn4');
}
And then you can call that function when you need to switch screens. (make a similar one for hideAll
.) For example, assuming you’re changing screens based on a button click:
onEvent("nextScreenBtn","click",function(){
setScreen("screen2");
showAllSaveBtns();
}
You can’t really get around needing separate event handlers for each of the buttons, but if they really all have the same functionality, you could write a function to handle that functionality and simply call it directly from each of the onEvent calls.
function handleSaveBtnClick(){
...
// do stuff that should be done when Save button is clicked
...
}
onEvent("saveBtn1","click", handleSaveBtnClick);
onEvent("saveBtn2","click", handleSaveBtnClick);
onEvent("saveBtn3","click", handleSaveBtnClick);
onEvent("saveBtn4","click", handleSaveBtnClick);
Not that in the above I’m also using a short cut to call the function. What’s above is equivalent to the more verbose inline function definition you get when you drag the onEvent block out of the tool box. This works too:
onEvent("saveBtn1","click", function(){
handleSaveBtnClick();
});
Hope that helps?
Baker
CSP Team
P.S. The “sophisticated” version I mentioned is to maintain lists, also called arrays, of the elementIDs that represent the items on each each screen. When you want to show a new “screen” you iterate over the lists of elements to hide what needs to be hidden and showing what you want to show. Composing this screen in Design Mode is a bit nightmarish because you have to see ALL possible elements at the screen at the same time…but it can be done!