Maybe missing something. Is there a way to refresh or update a markupgrid without calling the scene again. For instance I have a markupgrid with contents set and displaying on screen. When a particular event occurs, the content node of the markupgrid is changed. Other than calling the scene, is there a way to reflect the content change in the markupgrid?
The component xml file has the field. This is basically a copy from the sdk for markupgrid.
I have an observerfield that triggers correctly and resets the content. I then reset the markupgrid content to the content but the markupgrid on the screen doesn’t change. Something like
After content node has been changed I have the following in a function. I know the content is changed, I have checked this.
function refreshGrid()
m.myMarkupGrid = m.top.findNode("myMarkupGrid")
m.myMarkupGrid.content= m.global.posterx.shows
m.myMarkupGrid.SetFocus(true)
end function
I can get it to work if I call my main scene again, which makes sense but that’s not what I need to do. Calling the main scene again destroys everything and resets all elements. Thought there might be a refresh or redraw.
Thanks
I think the proper way to do this is to create a new markupgrid node and replace the existing node from above, by assigning the new node to an observed node field that the parent will see and “replacechild” with the new node.
maybe something like
function refreshGrid()
newMarkupGrid = CreateObject("myMarkupGrid")
newMarkupGrid.content= m.global.posterx.shows
' skipping the step here of assigning to a field that the parent observes, pseudo code'
m.parent.replaceChild(newMarkupgrid, index)
end function
you’ll need to first find and set the right m.parent and index values for this to work.
“joetesta” wrote:
I think the proper way to do this is to create a new markupgrid node and replace the existing node from above, by assigning the new node to an observed node field that the parent will see and “replacechild” with the new node.
maybe something like
function refreshGrid()
newMarkupGrid = CreateObject("myMarkupGrid")
newMarkupGrid.content= m.global.posterx.shows
' skipping the step here of assigning to a field that the parent observes, pseudo code'
m.parent.replaceChild(newMarkupgrid, index)
end function
you’ll need to first find and set the right m.parent and index values for this to work.
Let me see if I understand. In order to update the existing grid, I first create a second component called newMarkupGrid in this case. I set the content of new component to my updated content (m.global.posterx.shows). I then have to find the parent of the grid and replace that grid with the new grid (along with it’s content) at the appropriate index that the original grid is located. Ok, if this is correct I understand. Now, I am not sure how to get the parent or index. I know the grid is a child of my “HomeScene” which is the main scene of the app that is called. But I also have a busy spinner scene that is running prior to the HomeScene, so little lost on which is parent.
“Now, I am not sure how to get the parent or index.”
hmm in this case the markupgrid is a child of m.top, so you need to find the child index position under m.top;
for i = 0 to m.top.getChildCount()-1
child = m.top.getChild(i)
if child.id = "myMarkupGrid"
index = i
exit for
end if
end for
mewMarkupGrid.id = "myMarkupGrid"
m.top.replaceChild(newMarkupGrid,index)
“joetesta” wrote:
“Now, I am not sure how to get the parent or index.”
hmm in this case the markupgrid is a child of m.top, so you need to find the child index position under m.top;
for i = 0 to m.top.getChildCount()-1
child = m.top.getChild(i)
if child.id = "myMarkupGrid"
index = i
exit for
end if
end for
mewMarkupGrid.id = "myMarkupGrid"
m.top.replaceChild(newMarkupGrid,index)
that would all go instead of this line,
m.parent.replaceChild(newMarkupgrid, index)
Thanks again joetesta, this example along with your previous info helped greatly.
“joetesta” wrote:
“Now, I am not sure how to get the parent or index.”
hmm in this case the markupgrid is a child of m.top, so you need to find the child index position under m.top;
for i = 0 to m.top.getChildCount()-1
child = m.top.getChild(i)
if child.id = "myMarkupGrid"
index = i
exit for
end if
end for
mewMarkupGrid.id = "myMarkupGrid"
m.top.replaceChild(newMarkupGrid,index)
that would all go instead of this line,
m.parent.replaceChild(newMarkupgrid, index)
Thanks again joetesta, this example along with your previous info helped greatly. I would think there would have been a way to refresh, update or redraw, would have never thought you would have to replace one node with another. I guess as long as it work. Thanks a million.
“joetesta” wrote:
“Now, I am not sure how to get the parent or index.”
hmm in this case the markupgrid is a child of m.top, so you need to find the child index position under m.top;
for i = 0 to m.top.getChildCount()-1
child = m.top.getChild(i)
if child.id = "myMarkupGrid"
index = i
exit for
end if
end for
mewMarkupGrid.id = "myMarkupGrid"
m.top.replaceChild(newMarkupGrid,index)
that would all go instead of this line,
m.parent.replaceChild(newMarkupgrid, index)
Thanks again joetesta, this example along with your previous info helped greatly. I would think there would have been a way to refresh, update or redraw, would have never thought you would have to replace one node with another. I guess as long as it work. Thanks a million.
Something odd is happening to my children of the m.top. I actually have (2) grids. If I run the for loop above and print the child.id I can see each child of the parent. Once it finds the “myMarkupGrid” and exits the loop with the correct index and does the replace, all seems fine. Except that if I run the loop again to print the child.id right after the replace, the child just before the replace index is gone. For example, on the first run “myMarkupGrid1” is index 14 and “myMarkupGrid” is index 15. The loop finds the “myMarkupGrid” at 15 and does the replace. When the loop is ran a second time, the “myMarkupGrid1” is no longer present and the “myMarkupGrid” is moved to index 14. I noticed this when the “myMarkupGrid1” started disappearing from the screen after the function has ran. I can’t imagine a replace would remove a child from the parent and reindex the remaining. Is this a bug? I have tested this several times, which ever replace I do first, the child just before just after the found child is taken out of the list of children.
“joetesta” wrote:
that’s really strange, doesn’t seem like we’re replacing the wrong index. Any chance that second grid is a child of the first?
Well I thought maybe also, but both are from the m.top. I can run the loop twice and rem out the replace, all children show up. I am doing something a little different from your example
Where you had
newmarkupGrid= createobject("myMarkupGrid")
I done this
newmarkupGrid= myMarkupGrid
Nor sure if this is making it go wrong or not. It does return true for the replace but not sure why it removes the child before and after the replaced child, and even reindexed the children. Going to try something else and see if I can track it down. Just thought maybe the replace had a glitch.
Here’s a more detailed view of the problem. below is the sub that runs for find the child and replacechild. This is the replace for the first grid I have. The second grid is called PickList. I don’t have the code for it here since when it runs after MyGrid (refreshContent sub) the child is gone, so it disappears from screen.
sub refreshContent()
?"in refreshContent"
m.MyGrid=m.top.findNode("MyGrid")
for i = 0 to m.top.getChildCount()-1
child = m.top.getChild(i)
?"CHILD "child.id" "i
if child.id = "MyGrid"
?"MyGrid INDEX "i
exit for
end if
end for
m.MyGrid.content = m.global.posterx.show
m.top.replaceChild(m.MyGrid ,i)
?"REPLACEMENT "m.top.replaceChild(m.MyGrid ,i)
m.programmarkupgrid.SetFocus(true)
m.programmarkupgrid.visible= true
?"RESET CONTENT DONE"
for q= 0 to m.top.getChildCount() - 1
?"CHILD "m.top.getChild(q).id
end for
Ok, I am not creating a new child, but setting the content to new content that was downloaded.
Below is the debug from the initial for loop thru the children. Notice it finds MyGrid at 15. Also not PickList at 14.
yeah it’s a bit buggy! maybe what’s happening is since you’re replacing the item with itself it ends up doing two removals. Create a new node fresh and replace the old one, don’t try to re-use it like that and I think it will resolve the problem.
Well joetesta, I think I tried it all with same result. Using the replacechild wants to remove the child preceding the child replaced. No idea why, actually put some dummy children in before it and with each pass of the loop it removed them and kept going up the tree. But after all this I did find a solution which may be helpful to others that may run into the same thing. I am making a copy of the existing child something like
m.newchild= m.oldchild
this copies all existing info from old child. I then set my m.newchild.content to the new content. After this I removechildindex of the oldchild and append the newchild. This puts the newchild at the end of the children. By doing this, it no longer removes any other children in the list. No idea why replacechild doesn’t work for me, but this seems to do the job. Thanks for looking over it with me and giving me ideas.
It does load new content but the grid still doesn’t update, not until the event occurs a second time then it updates the grid.