The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Cybo (6) [Avatar] Offline
#1
Thx Dave for that fascinating book

But im stucked now smilie
I have created a class in which i wanne call the contentloader.

var ScourceWindow=Class.create();

ScourceWindow.prototype = {

initialize: function(el, sUrl){

this.el.Obj = el;
this.scourceURL = sUrl;

this.loader1=new net.ContentLoader( this.scourceURL, this.displayContent);
},


displayContent: function(){
this.RString= this.req.responseText;
this.dom = this.stringToDOM(this.RString);
var test3 = dom.getElementById('content').innerHTML;
$('scourceContent').innerHTML = test3;

}
};

btw. Thats not the whole code. The method stringToDOM() is also in the class.
My Problem is, that "this" of "this.RString" isn't the reference of my Classobject anymore. What Im doing wrong?
Pascarello (208) [Avatar] Offline
#2
Re: Problem with "this" at Contentloader(url, this.method)
(Hey I wrote it too!) lol

this should do it for you...

var ref = this;
this.loader1=new net.ContentLoader( this.scourceURL, ref.displayContent);

I think appendix B might talk about this

Eric
Cybo (6) [Avatar] Offline
#3
Re: Problem with "this" at Contentloader(url, this.method)
oh sorry also thx to Pascarello, and let me guess James too? smilie

but now thx for ur fast reply, ur advise changed something. But still not in the right way, hope u know why, coz have read the Appendix, but still have a problem with (this).

Uhm now in the function displyContent, the reference of "this" has an XMLHttpRequest-Object. onload-, onerror-,loadXML, onReadyState and defoulterror-function smilie

but not the Object-functions of my Class smilie.
Pascarello (208) [Avatar] Offline
#4
Re: Problem with "this" at Contentloader(url, this.method)
whoops, sorry was not thinking, you need to do a closure

var ref = this;
this.loader1=new net.ContentLoader( this.scourceURL, function(){ref.displayContent(this.req);});


so the first argument in the displayContent will hold the request object and you will still have the reference you are missing.

Eric
Cybo (6) [Avatar] Offline
#5
Re: Problem with "this" at Contentloader(url, this.method)
wow, thx a lot
thats it, damn I couldn't think also, or better I can't think in this way.

wont be the last question smilie

cya Cybo
Pascarello (208) [Avatar] Offline
#6
Re: Problem with "this" at Contentloader(url, this.method)
Glad I can help out!

Eric