First I’m reading the xml file and getting the info I want with this script:
local myData = require( "mydata" ) -- custom made global variables local xml = require( "xml" ).newParser() local audioFromXML = xml:loadFile( "getAudio.xml" ) myData.audioInfoXML = {} -- for each "child" in the audioFromXML table... for i=1,#audioFromXML.child do -- store the address in the audioInfoXML table myData.audioInfoXML[i] = audioFromXML.child[i] end -- for each audioInfoXML, print data to terminal for i=1,#myData.audioInfoXML do -- extract data from table and store in Local variables -- for easier readability/access: local songTitle = myData.audioInfoXML[i].child[1].value local audioDLink = myData.audioInfoXML[i].child[2].value -- print audioInfoXML data to terminal print( "Song Title: ", songTitle ) print("Audio Download Link: ", audioDLink ) end
And I’ve made a variable global (with the myData method) so I can acces it in my new scene (scene1) (I’ve done this with storyboard)
Then in scene1:
local myData = require( "mydata" ) -- Custom made global variables local widget = require( "widget" ) local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local halfW = display.contentCenterX local halfH = display.contentCenterY -- Our scene function scene:createScene( event ) local group = self.view print( #myData.audioInfoXML ) for i=1,#myData.audioInfoXML do local songTitle = myData.audioInfoXML[i].child[1].value print(songTitle) end -- Display a background local background = display.newImage( "assets/background.png", display.contentCenterX, display.contentCenterY, true ) group:insert( background ) local contentText = display.newText( songTitle, halfW, halfH, native.systemFont, 18 ) contentText:setFillColor( 0 )
Then I’m getting this error:
File: /Users/ernstluring/Documents/Corona/App1/page1.lua Line: 33 Bad argument #1 to 'newText' (string expected, got nil)