Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: widget.system asynchronous use from javascript object not working



 - first, the second argument to widget.system is a reference to a function, not an actual function call. Leave off the brackets, (), to pass the function as an argument. Currently you are passing it the result of the function which is being called immediately.

 - second, when using an asyncronous call the results of the call are passed as an argument to the function called, so _temporarySystemCall is not needed.

 - third, since this is a method of an object you will want to pass it a bound reference to the method since _javascript_ has a nasty habit of changing the definition of 'this'. I prefer to use bind() from prototype.js since it is simple and licensed such that it can be recopied at will.


If you'd like to take my advice then your call will become this:

widget.system ("/usr/bin/id -un", this._temporaryGetUserName.bind(this));

Hope that helps,

N


On 8/29/06, Gustav Axelsson <email@hidden> wrote:
I'm trying to call widget.system asynchronously from a _javascript_ object but I cannot get it to work properly.
It does work if I specify null instead of an endhandler but since we are not supposed to use null anymore I would like to do it "the proper way" even from within an object.

Here is the problematic section of my source code (_temporaryGetUserName crashes the widget):

function XmltvBack() {
    this._userID = "";
    this._temporarySystemCall;

    this._doneButton = new AppleGlassButton( document.getElementById("backDoneButton"),"Done",this.doneButtonPressed());
    this._usersChannels = new Array();
    this._usersChannelsHash = new Array();
    this._channelsXmlIsReady = false;
    this._channelsXml;
   
    this._temporaryInstaller();
   
}

var globalXmltvPath;

XmltvBack.prototype._temporaryInstaller = function(){
    document.getElementById("debug").innerHTML = "_temporaryInstaller körs";
    if(window.widget){
        document.getElementById("debug").innerHTML = "username = "+widget.system("/usr/bin/id -un", null).outputString; // Works!
        this._temporarySystemCall = widget.system("/usr/bin/id -un", this._temporaryGetUserName()); // Does start the endHandler but this._temporarySystemCall is undefined - why? :-(
    } else
        this._temporaryGetUserName();
}

XmltvBack.prototype._temporaryGetUserName = function(){
    document.getElementById("debug").innerHTML = "_temporaryGetUserName running";
    if(window.widget){
        document.getElementById ("debug").innerHTML = "_temporaryGetUserName is about to save this._userID";
        this._userID = ""+this._temporarySystemCall.outputString; // Row 29. Crashes the widget since this._temporarySystemCall is undefined
        document.getElementById("debug").innerHTML = "userID= "+this._userID;
    } else {
        this._userID = "gusax840";
        alert("_continueStartup running");
    }
    globalXmltvPath = "/Users/"+this._userID+"/Library/Xmltv/";
    this._channelsXml = new XmltvChannelsXml(globalXmltvPath+"server/channels.xml",this);
}

I've attached the widget as a zip file. The above code can be found in _javascript_/XmltvBack.js starting on row 1. Please note that the widget will crash on row 29 if you open it in Dashboard. It works in Safari though, if you want to see how it should look like.

Gustav


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      ( email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/dashboard-dev/email@hidden

This email sent to email@hidden





--
Nate
  -------
heagy.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/dashboard-dev/email@hidden

This email sent to email@hidden

References: 
 >widget.system asynchronous use from javascript object not working (From: "Gustav Axelsson" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.