douglas272

Q: Referring to another page with js in iAd Producer

I am developing a multi-page widget in iAd Producer, for use in an iBook.

I can't seem to suceed in referring to an object on a different page than the page containing the js.

 

For example, if I'm executing js on page myFirstPage, how do I refer to myObject on mySecondPage?

Thanks anyone.

Mac OS X (10.7.3)

Posted on Dec 10, 2013 11:20 AM

Close

Q: Referring to another page with js in iAd Producer

  • All replies
  • Helpful answers

  • by patixa,Helpful

    patixa patixa Dec 10, 2013 2:26 PM in response to douglas272
    Level 3 (617 points)
    Dec 10, 2013 2:26 PM in response to douglas272

    If an object is in the document and has a unique id, it can be retrieved via:

         iAd.View.getViewById("view-id");

     

    The identifier for views created by iAd Producer are usually "PageName-viewoutletname", or in your example, "mySecondPage-myObject".

  • by douglas272,

    douglas272 douglas272 Dec 11, 2013 11:23 AM in response to patixa
    Level 1 (0 points)
    Dec 11, 2013 11:23 AM in response to patixa

    Thanks much for your answer.

    I'm still not having success, however.

    I put the following two lines in my first iAd page in onViewControllerViewDidAppear:

     

    var theLabel = iAd.View.getViewById("mySecondPage-myObject");

    alert (theLabel.text);

     

    I get a js execution error that ".. null is not an object".

     

    Yet, if I put the following lines in  a button's onViewActivate in myPageTwo, I get the correct contents of the label object:
    var theLabel = this.viewController.outlets.myObject;
    alert (theLabel.text);
    Thanks for any help you can provide.
  • by patixa,Solvedanswer

    patixa patixa Dec 12, 2013 1:36 PM in response to douglas272
    Level 3 (617 points)
    Dec 12, 2013 1:36 PM in response to douglas272

    Depending on how the content is loaded, it's possible that page two is not yet defined within the context of page one. In such a scenario, I would recommend you follow standard MVC practices and set a variable to represent the changing state that the object on page one is toggling. In page two's "Page Did Appear", update the appropriate child object based on the variable modified by page one.

     

    Does that make sense?

     

    If not, can you provide a little more detail on what you are trying to accomplish, and I will cite or try to create an example to demonstrate what I mean using your scenario.

  • by douglas272,

    douglas272 douglas272 Dec 13, 2013 10:12 AM in response to patixa
    Level 1 (0 points)
    Dec 13, 2013 10:12 AM in response to patixa

    Thanks, I understand.

    I see that even if I, as a user, go to the seond page, then return to the first, the first page cannot see the

    text that is sitting in the text field of the second page.

     

    So, I'll use your suggestion and just store the content of the text field in a variable, when it changes.