Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
a question related to URL loader class — Gideros Forum

a question related to URL loader class

ashlyn_scottashlyn_scott Member
edited September 2012 in General questions
 
i = 0
q = ""
while (i<2)
do
	local loader = UrlLoader.new("<a href="http://localhost/example.php&quot" rel="nofollow">http://localhost/example.php&quot</a><img class="emoji" src="http://forum.gideros.rocks/resources/emoji/wink.png" title=";)" alt=";)" height="20" />
 
	local function onComplete(event)
		print(event.data)
		q = event.data
	end
 
	local function onError()
		print("error")
	end
	local function onProgress(event)
		print("progress: " .. event.bytesLoaded .. " of " .. event.bytesTotal)
	end
 
	loader:addEventListener(Event.COMPLETE, onComplete)
	loader:addEventListener(Event.ERROR, onError)
	loader:addEventListener(Event.PROGRESS, onProgress)
 
	i = i + 1
	print ("q1 : " .. q)      ---q is nil here .Why??
end
 
print ("q : " .. q)                   -----q is nil here .Why??
Although q is global and assigned a value , why is it still nil?

Comments

  • Do you mean "nil" as in the code generates an error or does it print "" (ie nothing)?

    The simple (and trite) answer is that "you told it to!" - not helpful I know :) it might be more helpful if you add in a couple more print statements and then copy and paste the output window contents.

    It *might* be because event.data is nil because your local server might not have served the example.php file correctly. Try pinging http://google.com and see what you get back from there.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • I get the below code from Reference Manual .It works with my URL(example.php):
     
    local loader = UrlLoader.new("<a href="http://example.com/image.png&quot" rel="nofollow">http://example.com/image.png&quot</a><img class="emoji" src="http://forum.gideros.rocks/resources/emoji/wink.png" title=";)" alt=";)" height="20" />
     
    local function onComplete(event)
        local out = io.open("|D|image.png", "wb")
        out:write(event.data)
        out:close()
     
        local b = Bitmap.new(Texture.new("|D|image.png"))
        stage:addChild(b)
    end
     
    local function onError()
        print("error")
    end
     
    local function onProgress(event)
        print("progress: " .. event.bytesLoaded .. " of " .. event.bytesTotal)
    end
     
    loader:addEventListener(Event.COMPLETE, onComplete)
    loader:addEventListener(Event.ERROR, onError)
    loader:addEventListener(Event.PROGRESS, onProgress)
    But in my code , i tried to assign event.data to a global variable in each loop. And then i want to print them
Sign In or Register to comment.