Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
groman00
Visitor

Cloning ContentNode

I have a Scene with two custom screens on it. One screen is a landing page with a RowList, containing multiple rows of videos. When a user selects an item from one of the rows, it will launch a video screen on top of the first screen. The goal is to have the content from the focused row on the first screen to be passed to the video screen, so there can be a single row at the bottom of the video player.

Passing the row content to the video screen is the easy part, but when I close the video player, the row content that I passed is missing from the landing screen. Clearly, my use if "appendChild" in the VideoScreen.brs code below is causing the original row content to change. I'm looking for a way to clone the row content, as to not affect the original content. Or possibly another way to structure my contentnode so I can easily pass nodes around without modifying them.


'' **
'' MainScreen.brs
'' **

function getPlaylistsContent()
? "loading playlists"

m.playlistsContentRequest = createObject("roSGNode", "playlistsContentRequest")
m.playlistsContentRequest.uri = m.top.playlistsContentUri
m.playlistsContentRequest.observeField("content", "showPlaylists")
m.playlistsContentRequest.control = "RUN"
end function

sub showPlaylists()
? "showing playlists"

m.playlists = m.playlistsContentRequest.content
end sub

function playlistItemSelected()
print "this is how the playlist is passed to the video screen"

m.videoScreen.playlist = m.playlists.getChild(m.rowItemSelected[0])
end function



'' **
'' PlaylistContentRequest.brs
'' **

sub getContent()
util = Utils()
content = createObject("RoSGNode", "ContentNode")
request = ParseJson(util.getStringFromURL(m.top.uri))
response = request.response

for each playlist in response.data.playlists
playlistItem = content.createChild("ContentNode")
playlistItem.title = playlist.name

for each item in playlist.items
videoData = item.video
video = playlistItem.CreateChild("VideoItemData")
video.title = videoData.title
video.hdPosterURL = videoData.thumbnailList[1].url
video.sdPosterURL = videoData.thumbnailList[2].url
end for

end for

m.top.content = content
end sub



'' **
'' VideoScreen.brs
'' **

function playlistChanged()
print "Playlist loaded to video screen"

data = CreateObject("roSGNode", "ContentNode")

''This is where I want to clone or shallow copy m.top.playlist
data.appendChild(m.top.playlist)
m.playlistRow.content = data
end function


Please help!
Greg Roman
Senior Software Engineer, AOL Alpha
0 Kudos
2 REPLIES 2
TheEndless
Channel Surfer

Re: Cloning ContentNode

I was recently looking for similar functionality and found it couldn't be done in 7.0. My understanding is that there will be some new reflection methods in 7.1 that will make it possible to clone nodes like this, but for now you may need to either hard-code the fields, or, if it's a custom content node, parse the component XML with roXMLElement to get the fields via the <interface> node.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
groman00
Visitor

Re: Cloning ContentNode

I was recently looking for similar functionality and found it couldn't be done in 7.0. My understanding is that there will be some new reflection methods in 7.1 that will make it possible to clone nodes like this, but for now you may need to either hard-code the fields, or, if it's a custom content node, parse the component XML with roXMLElement to get the fields via the <interface> node.


Thanks! I have a workaround for this now, which gets the job done. I'll keep an eye out for the 7.1 update.
Greg Roman
Senior Software Engineer, AOL Alpha
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.