Help Topics Version 2.0

Toggle Visible Action

With Show and Hide actions you can switch the visibility of a components on and off, but you need two different components to trigger the actions. To do the same using just one trigger component you can use the Toggle Visible action.

Creating a Toggle Visible Action

Select the component to trigger the action. Go to the Actions tab in Inspector and click the button below the Actions list. Then select the Toggle Visible action from the pop-up menu.

You can now select the Event, Receiver, and other general settings for the action. For more information on general settings of actions, see Using Actions.

Using Toggle Visible Actions

With a click on the corresponding component, the action renders the visibility of a component on and off. Only rarely will it make sense that the component triggering the Toggle Visible action is also the receiver component of the same action. In this instance, the component would go invisible after and then stay unavailable to trigger further actions.

If you need such a construction, you should provide some alternative way of making the component visible again. For instance, you can use another button to toggle the visibility back on. As an alternative, you can use timer events to restore components that have rendered themselves invisible.

Work Example

In this example, a Toggle Visible action is used to switch back and forth between two layers. You can find this example project as part of the Screencast 2.0 project, which is also treated in the screencasts on the same page. Since the settings have already been made in the demo project, you can follow these steps to see how it was done.

There are two layers in this project. To switch between them, the button labeled "Button Switch" is used. To achieve this, proceed as follows.

  1. Start by selecting the "Button Switch" button in the Scene Manager.
  2. Click on the Actions tab of the Inspector.
  3. Click on the button and select the Toggle Visible action.

Now that we have created a Toggle Visible action, we need to make some adjustments to it.

  1. Start by choosing an event to trigger the action. In this case take Clicked.
  2. Now choose a receiver for this action, in this case "Template Touch".
  3. The remaining properties are not relevant for this Toggle Visible action. Since rendering a layer invisible automatically hides the components contained in it, there's also no need to select the Send to Children option.

By now, the action would toggle the visibility of one layer, but we wanted to toggle between two layers so that one of them is visible at any time.

To complete this goal, create a second Toggle Visible action with the other layer as the receiver. It is essential to set one layer as visible and the other as invisible in their initial states in order for this to work. Otherwise both will appear and disappear at the same time.

© ~sedna gmbh 2016