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
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.
-
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?
-
You can access labely's properties by using
e.row.children[y]
(wherey
is the index of labely according to the order in which objects were added to the row). -
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(); });
-
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...