Published HTML5 acting different than localhost test

For developers using the Construct 2 Javascript SDK

Post » Sun Apr 03, 2016 3:32 pm

Hi

I'm working on another plugin, but struggling to find out why the code is acting different when it's published to a website, over running on localhost test.

I got this JS/jQuery code, that perfectly works when i'm testing, but not when i've exported the project.

Code: Select all
jQuery.each(self.response.results[0].address_components, function () {
   var component = jQuery(this)[0];
   jQuery.each(component.types, function () {
       console.log(jQuery(this));
       switch (jQuery(this).selector) {
           case 'street_number':
               self.data.street_number = component.long_name;
               break;

           case 'route':
               self.data.street = component.long_name;
               break;

           case 'locality':
               self.data.city = component.long_name;
               break;

           case 'administrative_area_level_1':
               self.data.state = component.long_name;
               break;

           case 'administrative_area_level_2':
               self.data.county = component.long_name;
               break;

           case 'country':
               self.data.country = component.long_name;
               break;

           case 'postal_code':
               self.data.postal_code = component.long_name;
       }
   });
});


The console.log will output the following on test (correct):
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]
Object[]

Where the Object selectors will have some value.
But the exported project will output this:
Object["s", "t", "r", "e", "e", "t", "_", "n", "u", "m", "b", "e", "r"]
Object["r", "o", "u", "t", "e"]
Object["l", "o", "c", "a", "l", "i", "t", "y"]
Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
Object["a", "d", "m", "i", "n", "i", "s", "t", "r", "a", "t", "i", "v", "e", "_", "a", "r", "e", "a", "_", "l", "e", "v", "e", "l", "_", "2"]
Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
Object["c", "o", "u", "n", "t", "r", "y"]
Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
Object["p", "o", "s", "t", "a", "l", "_", "c", "o", "d", "e"]
Object["s", "t", "r", "e", "e", "t", "_", "n", "u", "m", "b", "e", "r"]
Object["r", "o", "u", "t", "e"]
Object["l", "o", "c", "a", "l", "i", "t", "y"]
Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
Object["a", "d", "m", "i", "n", "i", "s", "t", "r", "a", "t", "i", "v", "e", "_", "a", "r", "e", "a", "_", "l", "e", "v", "e", "l", "_", "2"]
Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
Object["c", "o", "u", "n", "t", "r", "y"]
Object["p", "o", "l", "i", "t", "i", "c", "a", "l"]
Object["p", "o", "s", "t", "a", "l", "_", "c", "o", "d", "e"]

Why is this so ? Please help me. :)

-Acey
ImageImage
B
19
S
10
G
2
Posts: 52
Reputation: 2,072

Post » Mon Apr 04, 2016 10:45 am

It's probably broken by the minifier - see the section on Closure Compiler in the SDK docs: https://www.scirra.com/manual/22/runtime-overview
Scirra Founder
B
414
S
245
G
92
Posts: 25,201
Reputation: 200,343

Post » Mon Apr 04, 2016 11:29 am

Message: Acey can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Ashley wrote:It's probably broken by the minifier - see the section on Closure Compiler in the SDK docs: https://www.scirra.com/manual/22/runtime-overview


That seems pretty true for now, i've reworked the code to work without minifying, but how to i then oprimize it to work with minifying too, i think it's an cap for my plugins to say that people can't export with minifying if they use it.

EDIT:
TypeError: f.response.N is undefined is the error i get, when running here:
http://demo.acey.io/C2/LocationInfo/

I guess this comes from a try, catch i have, where the FOR loops are in.

Code: Select all
for(var componentIndex in self.response.results[0].address_components)
{
   var component = self.response.results[0].address_components[componentIndex]
   console.log(component);
   for (var typeIndex in component.types) {
       switch (component.types[typeIndex]) {
           case 'street_number':
               self.data.street_number = component.long_name;
               break;

           case 'route':
               self.data.street = component.long_name;
               break;

           case 'locality':
               self.data.city = component.long_name;
               break;

           case 'administrative_area_level_1':
               self.data.state = component.long_name;
               break;

           case 'administrative_area_level_2':
               self.data.county = component.long_name;
               break;

           case 'country':
               self.data.country = component.long_name;
               break;

           case 'postal_code':
               self.data.postal_code = component.long_name;
       }
   }
}
ImageImage
B
19
S
10
G
2
Posts: 52
Reputation: 2,072

Post » Tue Apr 05, 2016 8:19 am

There are 2 ways to name the property (variable or function name) in an object-
1. obj.name
2. obj["name"]

After exporting with minify, property name in Method 1 might be changed to obj.a, name in Method 2 will become obj.name. So uses Method 2 to keep the property name unchanged after minify.
Goodbye
B
114
S
31
G
295
Posts: 4,549
Reputation: 164,608

Post » Tue Apr 05, 2016 8:23 am

So your suggestion would be to always use method 2 ? If i understand correctly ? :)
ImageImage
B
19
S
10
G
2
Posts: 52
Reputation: 2,072

Post » Tue Apr 05, 2016 8:29 am

No, most of my property names uses method 1, only the names which I don't want to be changed uses method2.
For example, you put an external library into your plugin, call the functions provided by this library, then uses method2 to keep the name of function call unchanged.
Goodbye
B
114
S
31
G
295
Posts: 4,549
Reputation: 164,608

Post » Tue Apr 05, 2016 9:09 am

@rexrainbow Thanks for the explanation, after playing a little with it, i found out what you meant, and now i know the difference, thank you :)
ImageImage
B
19
S
10
G
2
Posts: 52
Reputation: 2,072


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests