Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
outputting a .txt file which usually updates itself - Page 2 — Gideros Forum

outputting a .txt file which usually updates itself

2»

Comments

  • @loves_oi: The error on line 10 in my example can be fixed by replacing line 10
    if stage:contains(sizeText) then stage:removeChild(sizeText) end
    with the following
    if sizeText and stage:contains(sizeText) then stage:removeChild(sizeText) end
  • loves_oiloves_oi Member
    edited August 2012
    @ar2rsawseen , :D :D i edited it . error is still the same :D
    @Scouser , ok i'm trying
  • This code works perfectly fine here:
    local alreadyLoading = false
    -- This is now your text
    local sizeText=nil
     
    local function onComplete(event)
    	local x = #event.data
    	print("size:", x )
     
    	-- If the text is on the stage already then remove it 
    	if sizeText and stage:contains(sizeText) then stage:removeChild(sizeText) end
    	-- now create your new text
    	sizeText = TextField.new(nil,"size : " .. x )
    	sizeText:setPosition(10, 265)
    	sizeText:setTextColor(0x007B25)
    	stage:addChild(sizeText)
     
    	alreadyLoading = false
    end
     
    local function onError()
    	print("error")
    	alreadyLoading = false
    end
     
    local function load()
    	if not alreadyLoading then
    		local loader = UrlLoader.new("<a href="http://www.catonmat.net/download/awk.cheat.sheet.txt&quot" rel="nofollow">http://www.catonmat.net/download/awk.cheat.sheet.txt&quot</a><img class="emoji" src="http://forum.giderosmobile.com/resources/emoji/wink.png" title=";)" alt=";)" height="20" />
    		loader:addEventListener(Event.COMPLETE, onComplete)
    		loader:addEventListener(Event.ERROR, onError)
    		alreadyLoading = true
    	end
    end
     
    local timer = Timer.new(60 * 1000, 0)  --it is updated every minute 
    timer:addEventListener(Event.TIMER, load)
    timer:start()
    load()
    I have just run it and it loaded 45722 bytes 3 times.
  • @scouser , it seems so sensible but it doesn't give the correct ouput .It can't delete the old one. I have tested again and again :(
  • OZAppsOZApps Guru
    edited August 2012
    @loves_oi, again I am not sure on what is it that you are trying to achieve. However, the correct way to do this would be

    1. Create the UI to display the information, i.e. create the textField and update this everytime you download the data
    local theText = TextField.new(nil, "placeholder")
    theText:setPosition(10,265)
    theText:setTextColor(0x007B25)
    stage:addChild(theText)
     
    theTime = TextField.new(nil,"timestamp")
    theTime:setPosition(10,285)
    theTime:setTextColor(0xffffff)
    stage:addChild(theTime)
    2. Create a function that encapsulates the downloading like,
    -- Function to download a file
    function download(theURL)
      local loader = UrlLoader.new(theURL)
     
      function onComplete(event)
        theText:setText("size : " .. #event.data)
        theTime:setText(os.clock())
     
        loader:removeEventListener(Event.COMPLETE, onComplete)
        loader:removeEventListener(Event.ERROR, onError)
      end
     
      function onError(event)
        theText:setText("Could not download the file")
      end
     
      loader:addEventListener(Event.COMPLETE, onComplete)
      loader:addEventListener(Event.ERROR, onError)
    end
    3. Call this function using a timer
    function load()
      download("<a href="http://www.catonmat.net/download/awk.cheat.sheet.txt&quot" rel="nofollow">http://www.catonmat.net/download/awk.cheat.sheet.txt&quot</a><img class="emoji" src="http://forum.giderosmobile.com/resources/emoji/wink.png" title=";)" alt=";)" height="20" />
    end
     
    local timer = Timer.new(3000,0)
    timer:addEventListener(Event.TIMER, load)
    timer:start()
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • and change the last double quotation mark on the url that keeps getting escaped on the forums.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • @OZApps , it worked correctly , thanks.
    Besides, thank everybody which helps . i appreciate them .
Sign In or Register to comment.