Warning: newbie alert:
I've seen similar on the forum but can't work this one out; My code is basically straight out of one of the examples and all the functions are inside a class.
class InputView extends WatchUi.View { // set up the response callback function // Straight out of the manual ... function onReceive(responseCode, data) {\ myDebug("onReceive() called with code=" + responseCode); // sdata = {}; // Reset our global data?? if (responseCode == 200) { sdata = data; // Do we need to copy it to make it global for some reason? Apparently we do! stationid = sdata.keys(); stations = sdata.size(); utclastsuccess = utctimenow(); changePage(pageid); } else { System.println("onReceive() failed. Response: " + responseCode); // print response code myDebug("Can't get data: " + responseCode); makeItRed("Can't get data :(", responseCode); } request_in_progress = false; } function makeRequest() { utclastchecked = utctimenow(); myDebug("makeRequest() called ..."); if (request_in_progress) { myDebug("makeRequest() aborting as request already in progress"); return; } var params = null; // var params = { "definedParams" => "someParam" }; var headers = { "Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED, }; var options = { :headers => headers, :method => Communications.HTTP_REQUEST_METHOD_GET, :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON }; // Make the Communications.makeWebRequest() call // Communications.makeWebRequest(url, params, options, method(:onReceive)); request_in_progress = true; Communications.makeWebRequest(url, params, options, method(:onReceive)); } function initialize() { View.initialize(); station_name = ""; wind_dir = "Getting data ..."; wind_speed = ""; last_update = ""; makeRequest(); // This works } function changePage(i) {
The initial call to makeRequest() and subsequent :onReceive callback work fine but I want to update the data from time to time if it gets old and if I try and call makeRequest() from inside the changePage() function it mostly bombs with this
Error: Symbol Not Found Error
Details: Could not find symbol 'makeRequest'
changePage() is in the same class and is called from another class that handles all the button pressing.
Is that the problem? Apologies as I'm sure it's a simple lack of understanding on my part but I just can't work it out.
EDIT: Further to this if I move changePage() out of InputView and make it global (where I guess it probably should be) and call InputView.makeRequest() I get the old
Error: Symbol Not Found Error
Details: Could not find symbol 'method'