Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Trusted Contributor
Posts: 152
Registered: ‎02-12-2011
My Device: Not Specified

using new Image()



I'm using the javascript Image Object to dynamically load a remote image. 


the code

var f = function(){
alert(typeof this);
var im = this;
var u = this.src;
alert(this.src); alert(this.width);
var w = im.width > window.screen.availWidth? window.screen.availWidth : im.width;
$('#event-image').attr('src',u).css({'width': w + 'px'});
if(blackberry.focus) blackberry.focus.setFocus('event-image');
delete this;
img = new Image();
img.onload = f;


works once but if the image is cached the this.src and this.width in the anonymous function is undefined! 


Why would this happen?


I note that in the blackberry browser reference the Image object is not referenced but the HTMLElement equivalent is!