Using Hotspot Property / Skin Variable in External JS file

Q&A about the latest versions
Post Reply
hromain
Posts: 42
Joined: Wed Apr 11, 2018 12:12 pm

I'm using an external JS file in my project to change the alt text of an external image component based on which hotspot is selected. I have tested it and am able to change the alt text successfully when using a string. Here's the code I'm using:

Code: Select all

function onLoad() {
  $(".popup-image > img").attr("id", "popup-image-id");
}

function changeAlt() {
  console.log("trying to change alt");
  $("#popup-image-id").attr("alt","test_alt_text");
}
Rather than keeping all the different alt text in the JS file, I want to author it in the P2VR project--either in the hotspot description or in a custom hotspot property. However, I can't figure out how to integrate the skin variables in the external function.

I tried testing this with a skin variable I'd set called "location," which is populated on hotspot mouse click. I tried the following, but it didn't work (alt text is changed to [object Object]). I know the variable itself works because I set a text box in the skin to show me the variable's current value.

Code: Select all

function changeAlt() {
  console.log("trying to change alt");
  $("#popup-image-id").attr("alt",$(location));
}
I think it's because the variable "location" isn't defined in the JS file, but I don't know how to do that. Any advice would be appreciated. Thanks!
Post Reply