Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Can't get picture from applicationDataDirectory to show.

I have some pictures in the Titanium.Filesystem.applicationDataDirectory. The alert picks them up:

("110-10-10", "110-10-10.png", "110-10-8.png", "110-10-9.png").

But I'm unable to set one of them as backgroundImage.

This is my first real project in Titanium.
Any help would be appreciated.

var win = Titanium.UI.currentWindow;

var date = new Date();
var day = date.getDate();
var month = date.getMonth();
var year = date.getYear();
var dpct = year+'-'+month+'-'+day+'.png';
var location = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory);
var dir = location.getDirectoryListing();

var images = [];

for (var i in dir) {
images.push(dir[i]);
}

alert(images);

win.backgroundImage = images[1];

— asked November 10th 2010 by David Aberg
  • iphone
  • mobile
0 Comments

1 Answer

  • Accepted Answer

    I think images[x] will return something like '110-10-8.png', which is not enough path information - you'd need to do something like win.backgroundImage = Ti.Filesystem.applicationDataDirectory+images[x] to get the fully qualified path to the image. Or, you could set backgroundImage to an actual File blob object returned from Ti.Filesystem.getFile.

    — answered November 10th 2010 by Kevin Whinnery
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.