Titanium Community Questions & Answer Archive

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

click one object and modify others

Let's say I have 2 separate objects in a table row - imagex and labely. How do I modify labely's title (or any of its attributes) when I click imagex?

the 'e' event object gives me access to everything I need concerning imagex since it is the object i clicked but i can't get to labely's attributes.

Thx

— asked April 30th 2010 by Kelly Redd
  • click
  • eventlistener
0 Comments

5 Answers

  • Maybe like this:

    imagex.addEventListener('click', function() {
    
        labely.text = "changed";
    
    })
    

    You will need to have labely present out of the scope of the function called by this event.

    — answered April 30th 2010 by Dan Tamas
    permalink
    0 Comments
  • Thanks Tamas, its funny I had already tried that before I posted but had no idea it was working b/c i've got 10 table rows and each click was affecting the last table row which way below the view port.

    soooo, technically it works but only sees the last iteration of the tableview loop. Each object has it's own eventListener so I would expect each click to reference the other objects in the scope of their table row, right?

    — answered May 1st 2010 by Kelly Redd
    permalink
    0 Comments
  • You can access labely's properties by using e.row.children[y] (where y is the index of labely according to the order in which objects were added to the row).

    — answered May 1st 2010 by James K
    permalink
    0 Comments
  • Thanks James, using e.row.children[], if i put the event listener below on my table view object it alerts and returns the correct value. but if i attach this to the object(s) i want to click it doesn't even alert.

    Is this not the intended use?

    // attach listener to an object - doesn't work
    projStatusImg0.addEventListener('click', function(e)
    {    
      var m = Titanium.UI.createAlertDialog({
            title:'data: ',
            message:e.row.children[0].text
        });
        m.show();
    });
    
    — answered May 1st 2010 by Kelly Redd
    permalink
    0 Comments
  • Solved! Just needed to add this line of code above each object i created in the loop.

    var projStatusImg0 = 'whatever'+i;
    
    var projStatusLabel0 = 'whatever'+i;
    
    etc...
    
    — answered May 2nd 2010 by Kelly Redd
    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.