science_01

Q: Linking Switch Objects (Two Objects = One Action)

Hello All,

 

I'm writing an iBook for my school, and using iAd producer to create a widget. Using arrows called with switches I'm singleing out specific structures on a anatomical drawing. I'm trying to discover a way so that an arrow appears only after two switches have been activated. For instance, to make a diagnosis the patient must present with two specific signs, and only then can we say that xxx is affeced. So, essentially I'm using the switch as a checkmark, and when two conditinos are met I would like the arrow to point to a location. Much thanks to jkahn117 who helped me with the deactivated switch state.

Posted on May 16, 2014 5:40 PM

Close

Q: Linking Switch Objects (Two Objects = One Action)

  • All replies
  • Helpful answers

  • by jkahn117,

    jkahn117 jkahn117 May 23, 2014 9:23 AM in response to science_01
    Level 1 (10 points)
    May 23, 2014 9:23 AM in response to science_01

    In order to achieve this functionality, you could extend our earlier example and utilize the ViewController itself to coordinate when arrows appear/disapper.

     

    For each switch, changing the passed string per switch (essentially an id for the switch or you could use the switch outlet's id):

     

    this.onControlValueChange = function (event) {
      this.viewController.switchChanged("switch1", this.on);
    };
    

     

    Then in the ViewController for the widget, you would check which switches are on to determine if an arrow should be shown.

     

    this.switchChanged = function(switchId, state) {
      if (state == true) {
        // check if paired switch is also on; if so, show arrow
        // you will need to think through how to manage the state of multiple switches
      }
    };
    

     

    You may also consider adding a reset button or additional logic that ensures only two switches are on at a time.

  • by science_01,

    science_01 science_01 May 23, 2014 10:34 AM in response to jkahn117
    Level 1 (0 points)
    May 23, 2014 10:34 AM in response to jkahn117

    Hello jkahn117, thank you for your response.

     

    So, I understand the first part about passing the string for each switch.

     

    this.onControlValueChange = function (event) {

      this.viewController.switchChanged("switch1", this.on);

    };

     

     

    However, I'm confused about how to combine these into an action:

     

    What is the location of the ViewControler for the widget?

     

    Also, what is the syntax for the instructions below? eg What is the code to check for paired switches?

    // check if paired switch is also on; if so, show arrow

     

    again, thank you very much I certainly appreciate your responses.

  • by jkahn117,

    jkahn117 jkahn117 May 23, 2014 12:18 PM in response to science_01
    Level 1 (10 points)
    May 23, 2014 12:18 PM in response to science_01

    The ViewController is the widget itself (called Page 1 in iAd Producer). Just click the Code button with the page selected.

     

    Without knowing more about your widget, it is hard to detail an exact solution.  For example, are there two specific switches that should be on at a given time (e.g. is the widget intended to ask a question) or can the user just toggle switches randomly to turn on arrows?  Either way, you will need some way to track the state of each switch (on/off) as well as which combinations turn on which arrows.

     

    My earlier answer simply guides on how to let the Page know that a switch has been turned on or off, that should be the basis for the more complex logic you will need to switch on the arrows.

  • by science_01,

    science_01 science_01 May 23, 2014 12:41 PM in response to jkahn117
    Level 1 (0 points)
    May 23, 2014 12:41 PM in response to jkahn117

    For example, are there two specific switches that should be on at a given time (e.g. is the widget intended to ask a question) or can the user just toggle switches randomly to turn on arrows?

    Exactly this, as you stated. The arrow should only display after two switches have been activated. For instance, toggling switch1 without switch2 "on" does not display an arrow, but if switch2 is "on" when switch1 is toggled then the arrow displays on the drawing.

     

    I'm hoping to present diagnostic cases, and as I speak my classmates will toggle the switches based on how the patient presents. So, for example, during the talk I give two hints (hint1 and hint2) for diagnosis1, and the user toggles switch1 and switch2 and arrow1 displays at location1. However, later in the talk I give two hints (hint1 and hint3) for diagnosis2, and the user toggles switch1 and switch3 with arrow2 displaying at location2.

     

    as before, i more than appreciate all the help. if i could buy you a beer i would.