Unexpected problems continued

Workarounds and usability notes.

Re: Unexpected problems continued

Postby Clifton » Wed Aug 23, 2017 10:25 am

This is really strange because after performing all its math calculations, snapObjectToCenter() simply calls pgTBObjSet() to position the objects. Since loading of snapObjectToCenter() occurs farther down in the browser loading sequence, I wonder if some of the PowerPac functions are being called before they are loaded. That would perhaps explain why some things work and some don't. By contrast pgTBObjSet() is among the first functions that become available in the DOM.

However, I'm not sure why your application would be accessing things even before ToolBook gets them loaded up for use.
Clearly, something strange is taking place.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Unexpected problems continued

Postby John Robin Dove » Thu Aug 24, 2017 3:54 am

Hi Clifton,

I think I may have found out a bit more about the strange error. It affects two different tbk files in the same way. I don't think it's anything to do with loading because you can reproduce the error long after loading has finished. External JS files are used for both these tbk files. Both are called b.js, obfuscated and copied to the media folder during the export process.

I sometimes replace the obfuscated contents of b.js with the non-obfuscated contents of the original JS file to allow me to modify and test functions in the exported file.

I have discovered that if I put back the snapObjectToCenter line (see below) in this way it works but if I try to export (and obfuscate) this line, it doesn't.

Code: Select all
// tbfunction_snapObjectToCenter("mover","page")     // DOES NOT WORK AFTER EXPORT!?
tbfunction_pgTBObjSet("mover", "left", 347);
tbfunction_pgTBObjSet("mover", "top", 231);


When I last tried this, this error message was displayed:

Image

It seems that the obfucation process is corrupting this line in the file.

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Unexpected problems continued

Postby Clifton » Thu Aug 24, 2017 4:39 am

YOUR CODE: (throws error)
tbfunction_snapObjectToCenter("mover","page")     // DOES NOT WORK AFTER EXPORT
tbfunction_pgTBObjSet("mover", "left", 347);
tbfunction_pgTBObjSet("mover", "top", 231);


TRY AGAIN WITH THIS CHANGE:
tbfunction_snapObjectToCenter("mover","page");     // DOES NOT WORK AFTER EXPORT
tbfunction_pgTBObjSet("mover", "left", 347);
tbfunction_pgTBObjSet("mover", "top", 231);


Obfuscation is really fussy when semi-colons are missing!
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Unexpected problems continued

Postby John Robin Dove » Fri Aug 25, 2017 4:12 am

Hi Clifton,

I really thought you'd cracked it this time. Your suggestion made perfect sense. But, believe it or not, it doesn't solve the problem! snapObjectToCenter still refuses to function after export. Here's a short video https://www.mediacours.com/tb_examples/snapObjectToCenter.mp4

I also checked if the missing semi-colon is a recent error. It isn't. The code was being exported without the semi-colon as long ago as last March and snapObjectTo Center was functioning normally at that time!?

John

P.S. This is all rather confusing because the last time I tried modifying the b.js file in situ snapObjectObjectTo Center worked after the modification. Now it doesn't. You could say it sometimes works but sometimes doesn't!
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Unexpected problems continued

Postby Clifton » Fri Aug 25, 2017 7:06 am

For what it's worth, I would get rid of the comments in this section of your script and delete and re-enter the snapObject... line as sometimes I've had PSPad enters hidden characters that cause interpreter issues. Also, put a semi-colon AFTER your definition of
var fct = function() {
...
};

Also, make sure your js file is saved with encoding as "UTF-8, no BOM"

Then try this and let me know the content of the alert:
alert( typeof window['tbfunction_snapObjectToCenter'] );
tbfunction_snapObjectToCenter("mover","page");
tbfunction_pgTBObjSet("mover", "left", 347);
tbfunction_pgTBObjSet("mover", "top", 231);


Result should be "function"
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Unexpected problems continued

Postby John Robin Dove » Sat Aug 26, 2017 3:36 am

Hi Clifton,

I removed all the comments and added a semi-colon as you suggested but snapObjectToCenter still produces an error. The encoding is UTF8 but I couldn't find anything about BOM in PS Pad.

Actually the encoding might just be the culprit because I remember now that I had to reset it to UTF8 because for unknown reasons it was set to ANSI during an export. This has happened in the past more than once.

The alert returns "function".

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Unexpected problems continued

Postby Clifton » Sat Aug 26, 2017 7:24 am

You can check and change the encoding of the file using the internal editor provided with the PowerPac. Just open your file using the menu item in the PowerPac menu and the NotePad3 editor that opens the file has an easy way to adjust this in the [file] menu. You should choose UTF-8 no signature. Each editor uses a little different nomenclature for BOM (byte order mark).

BTW: Does every browser throw the same error?
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Unexpected problems continued

Postby John Robin Dove » Sat Aug 26, 2017 9:50 am

I checked the encoding with the Powerpac internal editor. It is correct: UTF8 without signature.

I only use Chrome and Firefox (I could use Edge but if I remember correctly it's not compatible with all my requirements). Chrome gives the same error message as Firefox but with a little more detail:

The following error has occurred:

Uncaught TypeError: Cannot read property 'toString' of undefined (line number 1)
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Unexpected problems continued

Postby Clifton » Sat Aug 26, 2017 11:30 am

Can you send me a single page tbk with the exact object your are using called "mover?"

Thanks.
 
UPDATE:
Okay, I've found the issue and YES it involves snapObjectToCenter() but this is sort of a combination issue.
  1. When run from the Action editor it never fails.
  2. When run from a js or xml file it works fine as long as all parameters up to and including the [align] parameter is included.
In your case:
tbfunction_snapObjectToCenter( "mover", "page" );

This code fails because the ALIGN parameter is not specified. While the parameter help says that the default is to align 0 or "both" axis, it doesn't understand an undefined parameter. So it throws an error.

SOLUTION:
For now, you can add the align parameter like this:
tbfunction_snapObjectToCenter( "mover", "page", "both" );

I will make a bug fix and upload a patched PowerPac installation shortly.
 
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Unexpected problems continued

Postby John Robin Dove » Sat Aug 26, 2017 12:45 pm

Thanks Clifton,

I've just finished making the test app. It produced the same error. I was afraid it might not. It took me about an hour but I guess it's not much use to you now. Never mind. The main thing is that you've fixed the error.

I still don't understand why this error only showed up a couple of months ago. Before that there was no error even though I was using snapObjectToCenter in the same way.

John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron