[JS] Object identifier with minified c2runtime.js ?

Get help using Construct 2

Post » Wed May 20, 2015 8:22 pm

Hi.
I'm using this in my events :

Code: Select all
Browser.ExecJS("this.runtime.getObjectByUID("&Canvas.UID&").canvas.toDataURL('image/jpeg', 0.8);")


It appears that "Canvas.UID" seems to return nothing when c2runtime is minified : "TypeError: Cannot read property 'getObjectByUID' of undefined"

Why that ? How can I fix this while having my c2runtime minified ?
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Wed May 20, 2015 8:36 pm

It's "this.runtime" that's undefined. The minifier changes the name of "runtime" to something else. The only fix would be to do it in the plugin I suppose.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Wed May 20, 2015 9:11 pm

Thank you for your reply (and your correction of my misunderstanding of the error message :D).
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Wed May 20, 2015 9:21 pm

Read the warnings about executing JS code in the Browser object manual entry. In particular:

By default, code is minified on export. If you do not write Javascript that is compatible with Google Closure Compiler's ADVANCED mode, it may be broken and crash the game after export.


After minify, the runtime code is mangled so names like getObjectByUID are shortened to unpredictable strings like "xf". It doesn't look in strings though, so that action is broken.
Scirra Founder
B
397
S
236
G
88
Posts: 24,408
Reputation: 194,486

Post » Thu May 21, 2015 8:06 am

I guess I'll stick with a non minified code then :)
B
12
S
7
G
7
Posts: 450
Reputation: 4,276


Return to How do I....?

Who is online

Users browsing this forum: ASHKAR, brunopalermo, ItsAstro and 23 guests