Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1103] Setting a button image dynamically

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-10-28T12:36:52.000+0000
Affected Version/sn/a
Fix Version/sBacklog
ComponentsiOS
Labelsbutton, defect, dynamic, image, ios, iphone
Reporterctredway
AssigneeReggie Seagraves
Created2011-04-15T02:44:05.000+0000
Updated2011-10-28T12:36:52.000+0000

Description

A customer has been trying to set either the image or the backgroundImage of a button with an image downloaded from a site. The following code shows this bug.

var win = Ti.UI.currentWindow;

var imageView = Titanium.UI.createImageView({

backgroundColor: 'blue',
top:10,
left:10,
width: 125,
height: 89

}); win.add(imageView);

var photoButton = Ti.UI.createButton({

title: 'Click me',
top: 135,
left: 10,
width: 125,
height: 89,
backgroundColor:'blue',
backgroundImage: 'blah'

}); win.add(photoButton);

photoButton.addEventListener('click', function()
{

imageView.backgroundColor = photoButton.backgroundColor = 'red';
c = Titanium.Network.createHTTPClient();
c.onload = function() {
    var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'photo.jpg');
    Ti.API.info('Writing to:'+f);
    f.write(this.responseData);
    imageView.backgroundColor = photoButton.backgroundColor = 'green';
    //imageView.image = f;
    photoButton.backgroundImage = f;
    //imageView.image = photoButton.image = 'KS_nav_views.png'; // !!! QUESTION: why does cause a crash?
};
c.ondatastream = function(e) {
    ind.value = e.progress ;
    Ti.API.info('ONDATASTREAM2 - PROGRESS: ' + e.progress);
};
c.open('GET', 'http://www.appcelerator.com/wp-content/uploads/2009/06/titanium_desk.png');
c.send();

});

Comments

  1. Wilson Luu 2011-10-28

    Bug is not valid, does not reproduce in: TiMOB sdk version: 1.8.0.v20111027152620 Studio version: 1.0.6.201110251616 OS version: Mac OS X Lion Devices tested on: iphone emulator, iphone 5.0, ipad2 4.3.5

JSON Source