Creating multiple display.newText objects

Hi,

I will need to create 10 display.newText objects.
Then I will load data from a remote json source and update the text of these objects.

Is there a way to do this without repeating all the code for eache object? Maybe using a loop?

Thanks [import]uid: 189638 topic_id: 34630 reply_id: 334630[/import]

local textObjects = {} -- make a table  
for i = 1, 10 do  
 textObjects[i] = display.newText("",0, (i-1) \* 25, system.nativeFont, 20)  
 group:insert(textObjects[i]) -- if you need to insert it into a display group  
end  

Then later when you want to change the strings:

textObjects[5].text = "Fifth Object"  

[import]uid: 199310 topic_id: 34630 reply_id: 137677[/import]

The font should be native.systemFont :slight_smile: [import]uid: 70847 topic_id: 34630 reply_id: 137678[/import]

Thanks for the catch! It’s been a long week. :slight_smile: [import]uid: 199310 topic_id: 34630 reply_id: 137680[/import]

Thank you Rob.
That worked for me :slight_smile: [import]uid: 189638 topic_id: 34630 reply_id: 137867[/import]

local textObjects = {} -- make a table  
for i = 1, 10 do  
 textObjects[i] = display.newText("",0, (i-1) \* 25, system.nativeFont, 20)  
 group:insert(textObjects[i]) -- if you need to insert it into a display group  
end  

Then later when you want to change the strings:

textObjects[5].text = "Fifth Object"  

[import]uid: 199310 topic_id: 34630 reply_id: 137677[/import]

The font should be native.systemFont :slight_smile: [import]uid: 70847 topic_id: 34630 reply_id: 137678[/import]

Thanks for the catch! It’s been a long week. :slight_smile: [import]uid: 199310 topic_id: 34630 reply_id: 137680[/import]

Thank you Rob.
That worked for me :slight_smile: [import]uid: 189638 topic_id: 34630 reply_id: 137867[/import]

I have the same question, but the solution seems not to work in a scene =/

If you insert the object into the scene.view, it only shows the last one.

Any ideas?

Thanks!

No one?

Thanks!

I have the same question, but the solution seems not to work in a scene =/

If you insert the object into the scene.view, it only shows the last one.

Any ideas?

Thanks!

No one?

Thanks!