Calling a Function or Accessing a Variable in another Javascript File

Hello Again,

Been struggling with this one all morning, basically I have add a file called Interface.js which is set to include in the header to my resources which has a Function called ShowTeaching(); in it. I have created a new Javascript Function in Hype 3 called ToggleTeacher and I am trying to call the function in Interface.js as per below ;

// interface.js JavaScript Document

function showTeaching()
{
var element = document.getElementById(“showpic”);
element.style.visibility = “visible”;
}

function hideTeaching()
{
var element = document.getElementById(“showpic”);
element.style.visibility = “hidden”;
}

// End

My new Hype Javascript Function ;

Function ToggleTeacher(hypeDocument, element, event) {
$.getScript("${resourcesFolderName}/interface.js", function(){
// Use anything defined in the loaded script…
showTeaching();
});
}

… But Nothing Happens, is this the correct way to Achieve this ?

PART 2

Similar to above, I also have a Javascript file added to Resource which has a variable in it for JSON which is as below, I want to be able to read the “showpic” imgSrc from this file, is that possible to do in Hype ?

Javascript File p3.js

// JavaScript Document

// JSON字符串
var pageJson =
{
“KLHEAD”:
{
“info”:“No.03”,
“title”:“Monkey Fun”,
“css”:[],
“js”:[“p3a.js”,
“p3b.js”,
“anim03.js”]
},
“KLBODY”:
{
“spriteLayer”:
[
{
“name”:“bgb”,
“area”:[0, 0, defWidth, defHeight],
“zIndex”:1002,
“visibility”:1,
“animType”:0,
“imgSrc”:“p3.jpg”
},

				{
					"name":"monkey1",
					"triggerEnable":1,
					"triggerRect":[0, 8, 960, 414],						
					"visibility":1,										
					"animType":4,
					"animData":"monkey1",
					"audio":
						[
							{
								"audioPath":"p3.mp3",
								"audioTimeDelay":250
							},
							{
								"audioPath":"hanging.mp3"
							}
						],		
						"stopPosition":10,
                   
					"relatedPartId":"p3",
					"relevantFont":["p3"]
				},
				
			
				{
					"name":"showpic",
					"area":[teacherOffset, 0, teacherWidth, defHeight],
					"zIndex":4999,
					"visibility":0,
					"animType":0,
					"imgSrc":"fp03.png"
				}
				
			],
			"txtLayer":
			[
				{
					"name":"text1",
					"frame":[102, 803,1],
					"fontSize":46,
					"fontFamily":"ITCAvantGardeGothicMedium",
					"letterSpacing":3,
					"htmlCode":"<p><span id='p1'>I </span><span id='p2'>am </span><span id='p3'>hanging.</span></p>"
				}				 
			],
		"transLayer":
			[
				{
					"name":"translate",
					"txt":"I am hanging.@@我挂在树上。",
					"isLeft":1
				}
			],
			"pageCodeLayer":
			{
				"code":[2,3],
				"color":"#627994"
			}
	}

};

Hype3 Javascript ;

function GetPanelName(hypeDocument, element, event) {
$.getScript("${resourcesFolderName}/p03.js", function(){
// Use anything defined in the loaded script…
var sprites=pageJson.KLBODY.spriteLayer;
alert(sprites[2].name);
});
}

Would really appreciate some help with this, learning all the time…

Regards

JudgeyK

Can you share your Tumult Hype document as a zip file?

Thanks,
Daniel

Hi Daniel,

How do I share it here?, its about 10mb, do you have an FTP I can copy it too ?

Cheers

JudgeyK

You can share with this service: http://ge.tt
Thanks!

Here you go Daniel ;

http://ge.tt/9Ri1UUD2/v/0?c L1-1.zip (9.3 MB)

The functions are being called on the reader_focus_panel element (Image)

Cheers

JudgeyK

When I run the function, I get this error in the console:

Do you know what ‘extra.js’ is?

Do you have a regular HTML file that demonstrates this JavaScript library working or some sort of documentation you could link to?

Hi Daniel,

I can’t find an extra.js file anywhere , I have been given the all the attached files to develop an application around them and to play them which I have done before in WPF / vb.net. But this time I wanted to try doing it using Hype so I wanted to try and create a Hype3 Application which could host / download this file type as a Zip file and play them without affecting the original format too much.

I have found if I include the static.js file in the header some of the errors go away.

Do you thing the above is possible ? or should I go back to WPF ?

Checking the files for extra.js, I have found they have included it in the parser.js even though it does not exist anywhere in the original zip structure.

There is no file included, but its being called by a HTML Widget here:

I would go back to how sent you the files and ask for the extra.js as it needs it.