Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
loading url of each rows and then printing them — Gideros Forum

loading url of each rows and then printing them

loves_oiloves_oi Member
edited September 2012 in General questions
I have a table in database. For example,first screen looks like as:
c.b. Moskow
c.b Atina
c.b. Madrid
(c.b. = checkbox)
In database, for all countries , there is a url.
params[1]=checked or not params[2] =Moskow params[3] = www.moskow.com
params[4]=checked or not params[5] =Atina params[6] = www.Atina.com
params[7]=checked or not params[8] =Madrid params[9] = www.Madrid.com
Assume that , i select first and third row.Then it should load the datas from www.moskow.com and www.Madrid.com .
For example , it should load xMoskowx and xMadridx from these url . Then i want to do a screen which looks like as:
Moskow xMoskowx
Madrid xMadridx

I have wrote the below code for this reason.
 
results = Core.class(Sprite)
function results:init(params)
 
	local screen = Bitmap.new(Texture.new("resources/images/opt_back.png"))
	self:addChild(screen)
	screen:setPosition(0,0)	
	local txtY = 100
 
	the = {}
	p = 2
	local a = 1
	mySize = table.getn(params)
	k=1
 
	q = ""
 
function onComplete2(event)
			q = event.data
			the[p] = TextField.new(nil, "hello") 
                        the[p]:setPosition(100,50 +a*50) 
                        the[p]:setTextColor(0x007B25) 
                        the[p]:setScaleX(3)the[p]:setScaleY(3)
 
	--the[p]:setText(params[k+1])    doesn't work - Because k+1 is out of index - params[k+1] is nil.
	print("k : " .. k)
	print(params[k+1])  --nil is printed. But params[k+1] should be name of the shopping mall.
	print ("q = " .. q )    --It is the loaded data of the mall which is obtained from its url 
	stage:addChild(the[p])
	a = a + 1
end
 
while(k < mySize+1) do
	if (params[k] ==true) -- params[k] holds whether the related row is checked or not in checkboxes pages
	then
		p=k  -- assign k to global variable p. p is used in function onComplete2.
		local loader2 = UrlLoader.new(params[k+2]) 
                --params[k+2] holds the Url of each row which will be loaded
 
		loader2:addEventListener(Event.COMPLETE, onComplete2)
	end
		k = k+3
end
 
print ("q3 = " .. q)
 
---...
After incrementing the index k , i tried to load the related URL. i thought that, for each loop , it will call onComplete2 function .But it didn't call.


I thougt such an output :
k : 10 --After exiting while loop , it comes to onComplete function , i think. 10 is out of index
nil
q = XMoskowX

k : 10 --After exiting while loop , it comes to onComplete function , i think. 10 is out of index
nil
q = XMadridX

I think it is because of synchronization. But how can i fix this problem?
Thanks in advance.

Comments

Sign In or Register to comment.