Iterating through a set of widgets

I have a large set of dynamic panels and I need to trigger some actions if a particular dynamic panel has a specific state. In order to do this I need to iterate through the large set of dynamic panels. Is there a way to cycle through an array of widgets in Axure? Thanks for your time!

You can use the dynamic panel’s Panel State Changed event and conditional cases to trigger and control your actions. For example,

PANEL STATE CHANGED
Case 1
If state of This equals State2
Set Selected of MyOtherWidget to “true”

What do you mean by “iterate” here? Not clear what exactly is being iterated… Showing only one dynamic panel of many? Selecting only one dynamic panel? Do you have an example, sketches, or your .rp file that could provide more info?

  • What do you mean by “cycle through”?
    • Same as “iterating”?
    • Automatic “cycling” (e.g., show one every 5 seconds) or manual (e.g., user clicks a “Next” button)?
      What do you mean by “array” here? Technically, arrays are not supported in Axure, but I suppose you mean a “bunch” or “set” of widgets.

There are a number of methods you can use to “choose” or do something with “widget X” in a set of N widgets, but because they are not in a true array it can get complicated. Here are two basic approaches to consider. Let’s assume your iteration/cycle/choice of a widget is setting its Selection State to “true”, and you’ve assigned all widgets in your “array” to the same selection group (learn about Selection Groups in Axure.) …You can apply these to most/all events in Axure like Show/Hide, Move, etc. but a Selection Group ensures one and only one widget is selected at a time.

  • (1) Create a “chain link” from one dynamic panel (dp) widget to another.

    • Straightforward and simple, it requires the order of the cycling to always be the same (e.g., 1, 2, 3, 4, …) and works well for automated cycling.
    • For each widget assign a Selected event which either prepares for selecting the next widget, or automatically selects the next widget after a delay.
      • Essentially, each widget only needs to know about the widget next to it in the “chain.”
    • Automatic cycling is the easiest to explain here… When Widget1 is selected, it can wait N ms and then select Widget2:
      SELECTED
      Wait 5000 ms
      Select Widget2
    • You can copy & paste the Selected event from one widget to another and update the “target” widget. For example, on Widget2 you would have:
      SELECTED
      Wait 5000 ms
      Select Widget3
    • Adding and removing widgets in your set is fairly easy as you only need to change one or a few widgets’ Interaction code.
  • (2) Create a dp to act as a subroutine or function to control your “cycling”

    • More setup effort, but it offers more flexibility in the “cycling order”, skipping around, and easier manual “cycle changes.”
    • Set up this “subroutine dp” with one state per widget in your “array” (each state can be empty.) For example, if you have 20 dp widgets to cycle through, your subroutine would have 20 states and a Panel State Changed event with 20 conditional cases.
      • Each conditional case selects (or whatever action) the appropriate dp widget. For example:
        If State of This equals State1
        Select MyWidget1
        Else If State of This equals State2
        Select MyWidget2

      • For easier maintenance, I recommend naming your states the same as the dp widgets in your “array.”

      • You can change the “cycle order” by simply reordering the states in the dp.

    • To manually cycle through the array, just set the state of your subroutine to “Next” or “Previous”:
      Set Panel State of MySubroutine to Next
      • Include the “wrap” option to go from state N to state 1
    • To automatically cycle through the array, add an additional case of “If True”, include a delay and change state of your subroutine dp:
      If True
      Wait 5000 ms
      Set Panel State of This to Next

Thank you for taking the time to explain this for me @mbc66. I shall try your approaches.

It would have been a lot more easier for Axure users if there were indices for widgets with the same name so that we can loop through them or at the very least reference them without hardcoding their names every time. (But that may be just me!)

1 Like