FlashCats Flash Catalyst Tips N' Tricks

15Jun/10Off

How do I get components to reset after changing states?

When you transition between pages or states in Catalyst, objects remain just as you left them. If you moved a scrollbar or slider in Page 1, then transition to another page, the scrollbar or slider will be in the same position as you left it. Often, you would like these components to reset, so that when you come back to them, they appear as if you had arrived at Page 1 for the first time.

We'll talk a bit about why Catalyst behaves the way it does, and how to achieve the desired effect after the jump.

The Explanation Bit

Which I find interesting, but if you're just looking for a how to you can skip it.

Catalyst behaves according to a stateful model, which is just fancy talk meaning that Catalyst keeps track of the state that you left components in. Think about it this way. Say you are ordering a book online. You fill out a web form (Page 1) with your shipping address and credit card information, then press next. At the next page (Page 2), you realize you made a mistake and go back to the previous page (Page 1) to fix it. If the form is blank, then the form is behaving according to a stateless model, meaning the form doesn't preserve information when moving amongst pages. If the form contains your previously entered information, then it is behaving according to a stateful model, because the form is remaining in whatever state you left it. The terminology is great, right, because we have yet another notion of state (which is, mind you, different than Catalyst component states; we'll be getting to those shortly).

The Example

Here is an example of a custom component with several different "color" states, and a scroll panel. Notice how the different components behave if they are acting statefully or statelessly.

Get Adobe Flash player

How it Works

Put simply, we add a couple extra actions to the transitions from Page 1 > Page 2, and Page 2 > Page 1 in order to reset them to their initial state.

To get the Custom Component to reset, we select the component and open the timeline. For the Page 1 > Page 2 transition, we choose Add Action > Set State > State 1 (the initial state of the component). Whenever we transition from Page 1 > Page 2, the custom component will go back to its initial state.

To get the Scroll Panel to reset is a bit more difficult, because we can only work with the Scroll Panel's enabled and disabled states. To make matters more complicated, because it's not a Custom Component, we can't set its state directly. But, setting the enabled property will indirectly set the Scroll Panel's state. Here's what you do:

  1. Open the Scroll Panel in edit in place
  2. In the Normal state, select the scroll bar
  3. In the Properties Panel's Component section, set the value property to 1
  4. Switch to the Disabled state. Set the value property to 2
  5. Exit edit in place. Select the Scroll Panel you want to have reset to its initial scroll position.
  6. In the appropriate transition (in this case Page 2 > Page 1), choose Add Action > Set Property > Enabled > False. The Enabled and False options are to the right in the Properties Panel after you add the Set Property action.
  7. Add another Set Property > Enabled > True action and drag it out to occur just after the initial set property action.

And there you have it. By setting the enabled property to false, then true, you toggle the Scroll Panel between the Normal and Disabled states. This will adjust the value of the scrollbar, which will set the position of the Scroll Panel's content. Tricky, eh?

Some Notes

You need to explicitly set the Scroll Panel's Scroll Bar's value in each state to a different value. The values also need to be non-zero. If you leave the number as zero (the default value), the Scroll Bar will assume it can use the default value and won't explicitly set it. We need the values to be explicitly set in order for the Scroll Bar thumb's position to properly adjust. After you have set the two state's value property to different, non-zero numbers, you can go back and set one of them to be zero.

Posted by bear

Comments (15) Trackbacks (0)
  1. yo guys I LOVE your website. With Flash Catalyst and this website I can now make my own Flash Applications without writing codes n stuff(hate it). THANKS and please keep making tutorials for flash catalyst, so more designers can express themselfs!

  2. Thank you! Your explanation was exactly what I needed to get the logic. I have nine toggle buttons that on rollover tansition to another unique page, on rollout transistion back home and once selected display a “popup”–I was struggling with how to deselect a button, hiding its “popup,” as another was selected. Action Sequences saved the day! Loving this program more and more.

  3. Nice post. I am wondering if this can be applied to a video. I’m using the video player to play songs on different pages of my project. I would like the songs to restart when you click back to the page from another song/page, rather than restart where it was stopped. Is there a way restart the video at the beginning when returning to a page, similar to the scroll bar/component scenario about?

  4. Hi there,

    Stopping and starting the video in an action sequence or state transition should do it for you. They’re available under the “Add Action” button in the timeline panel.

  5. so it did. thank you!

  6. It’s easy…But I have Custom component within a swf created in another project of Catalyst. When I put the transitions as you indicate, step to another section and then go back to where I have the custom component, the swf is in the same position where I had left … What I can do?

  7. Hi there. You only ever have access to the current project in Catalyst. The custom component swf is probably maintaining its own state. To adjust this you would have to reload the swf using some Actionscript in Builder. It is something that you can’t do in Catalyst, at least not with the current controls it has for swfs.

  8. Hey, I had a similar question as Jessica, but my knowledge of Flash Catalyst is limited. I would like the video to restart when you click back to the page from another page, rather than restart where it was stopped. Do you add the action sequence or state transition to the video or button that controls the page. If so does the video or button have to be components first before you add the stopping and starting? I tried add the play and stop functions with the add action in the timeline panel, but I’m not sure what to do to get it to work. thank you for this informative site.

  9. Hi there,

    Stopping and starting a movie should restart it from the beginning. You add the action sequence as an interaction. Whatever starts the interaction, in this case the button, is what you should have selected when you add the interaction. The alternative way to play and stop the movie is through state transitions. This article on action sequences, or the end of this article with state transitions, may be of help.

  10. When I go to “Set Component State”, it is always “greyed” out. Why is that?

  11. Hi there,

    The component may not have states, or you may not be allowed to control the states (for example, in skins, the skinnable component is the only one allowed to set the skin states).

  12. Is there a workaround to Austin’s issue? I’m using datalists which unfortunately retain the select list item between states.

  13. Hi there,

    You can’t directly set the state of a skinnable component, because the skinnable component is supposed to be managing the states. The most you can do is set enabled/disabled (values) to toggle between the normal and disabled skin states.

    -Bear

  14. I cannot use this solution on radio buttons. After clicking a button on State1, I click to State2.Then I go back to State1 and I see the radio button I’ve clicked before is still clicked. I know it’s too complicated but I need an answer. I’m going crazy :) )

  15. Hi there,

    I think you may have to enable/disable the button when you change state.

    -Bear


Trackbacks are disabled.