roffe

Q: Making variables global i iAd Producer

sorry if this is a really simple question. Still, I am stuck:

I would like to have widgets access other widget's variables. I would have thought, for instance, that it would be possible to declare a variable

var Utility = this.viewController.outlets.Utility;

in Global.js, refering to a widget declared in one of the standard auxiliary (.js) files.

I assume that there are more clever ways of doing this. I'm not new to programming, but I'm new to both iAd Producer and JavaScript.

Any and all pointers welcome.

Thank you,

Posted on Mar 13, 2014 1:56 AM

Close

Q: Making variables global i iAd Producer

  • All replies
  • Helpful answers

  • by patixa,Solvedanswer

    patixa patixa Mar 13, 2014 7:44 PM in response to roffe
    Level 3 (597 points)
    Mar 13, 2014 7:44 PM in response to roffe

    For security reasons, each widget in an iBooks Author book can only access it's own content.

     

    If you meant sharing across pages in a project, then Global.js is the place to store the variables. It's best to assume Global.js can NOT see anything on individual pages, so your idea of using "this.viewController…" likely won't work. Instead, define your Utility class in Global.js (or in another JavaScript file you added as an asset), and reference the objects therein directly from the code in your pages.

     

    Does that help?

  • by roffe,

    roffe roffe Mar 14, 2014 3:30 AM in response to roffe
    Level 1 (0 points)
    Mar 14, 2014 3:30 AM in response to roffe

    Certainly, this made everything clearer! So what I do is I create a global object, and let widgets communicate through that object.

     

    I think that works!