Clearing Text generated Within a Function

Hi!

I’m new here and looking to build my first app using corona. I have encountered a bit of a hurdle that I was unable to solve and was hoping to get some assistance or be pointed in the right direction.

I have a table and a function that populates the screen using data from the table using the following snippet ofcode:

function populate()  
for i = 1,table.maxn(base),perset do  
  
  
 local p = display.newText(title.. " = ".. cost, \_W/4, \_H/4 + 25 \* i, system.nativeFont, 34)  
  
end  
end  

Basically the function goes through a table array and creates a text field for each entry.

The problem, of course, happens when I need to run this function again to populate a new set of values from the table… it overlaps the previous text on the screen.

Now I understand that this happens because I am declaring the text field within the function… but is there any efficient way for me to clear this text? [import]uid: 48775 topic_id: 8670 reply_id: 308670[/import]

every time you run this function a new set of text fields is created
create the text fields once outside the function, and use the function to set their text property

[import]uid: 6459 topic_id: 8670 reply_id: 31165[/import]

Unfortunately that does not help since in my implementation I needed to generate the fields within the function.

Howeve, I did just find a solution to this problem in this tutorial video: http://www.youtube.com/watch?v=KudLE8h4kWw

basically I just created a new group and made a function to clear the group

[code]
for i = grouptoclear.numChildren, 1, -1 do

if (grouptoclear[i].exists) then
grouptoclear[i].exists = nil
grouptoclear[i]:removeSelf()
grouptoclear[i] = nil
end
end
[/code] [import]uid: 48775 topic_id: 8670 reply_id: 31169[/import]