Skip to main content
Known Participant
December 10, 2009
Question

ns.onStatus , scope, and this

  • December 10, 2009
  • 1 reply
  • 288 views

I am little confuse on how to use 'this' and scope issue when working on FMS and onStatus (just confuse in general).

In the example below I have a function that gets a bunch of calls and I need to track the status of the stream. Since ns.onStatus is a async callback I how do make sure I update the right nsArray[] with the status. I may be over working this but I need some help.

LM.prototype.nsStartit =function(clientObj,nc,nsIndex,streamObj,toIP){

var tempNS;

     tempNS = nsStream(clientObj,streamObj,nsIndex,nc,toIP);

     nsArray[tempNS].ns = new NetStream(nc);

     nsArray[tempNS].ns.attach(streamObj);

     nsArray[tempNS].Stat = false;

     nsArray[tempNS].ns.onStatus = function (info) {

     if ((info.code) == "NetStream.Publish.Start") {

          nsArray[tempNS].Stat = true;  // Is this the way

          nsArray[this.tempNS].Stat = true; // or is this way

     // and would I also need tto do the same for var that

     // I pass via prarm like 'toIP'

     // would I ref 'this.toIP' or just 'toIP'

     }

  }

nsArray[tempNS].ns.publish(streamObj.name, "live");

}

    This topic has been closed for replies.

    1 reply

    Known Participant
    December 15, 2009

    The answer is as follow,

    .this means the object context code is in - so in order to make sure I am accessing correct tempNS within nsStatus I need to assign

    nsArray[tempNS]. tempNS = tempNS;  // do this before async call - nsStatus

    This would be one way to make sure I am using correct value within async call back.

    So than I can see correct 'tempNS. using

    this.tempNS;

    within nsStatus func

    Thanks