加载远程图像后,向侦听器添加ID

时间:2013-12-11 15:58:00

标签: lua listener corona

我有一个用于加载远程图像的监听器,但是我需要能够将ID号传递给该监听器,而我真的不知道该怎么做。我检索远程图像的代码是:

display.loadRemoteImage("http://www.newyorker.com/online/blogs/photobooth/NASAEarth-01.jpg", "GET", networkListener, "banner.png",system.TemporaryDirectory,  (globalData.contentX * rows2) + globalData.contentX/2, 20 + (i - 1) % 6 * 140

我的听众是:

local function networkListener( event )
    if ( event.isError ) then
        print ( "Network error - download failed" )
    else
        local target = event.target
        target.alpha = 0
        transition.to( target, { alpha = 1.0 } )
        target.width = 590
        target.height = 110 
        target:addEventListener( "touch", target )
        scrollView:insert(target) 
        function target:touch(event)
            if event.phase == "began" then
                display.getCurrentStage():setFocus( self )
                self.isFocus = true

            elseif self.isFocus then
                if event.phase == "moved" then
                    numMoved = numMoved + 1
                    if(numMoved > 10) then
                        display.getCurrentStage():setFocus( nil )
                        self.isFocus = false
                        scrollView:takeFocus( event )
                    end
                elseif event.phase == "ended" or event.phase == "cancelled" then
                    globalData.selectedLocationID = target.id --This needs to be the ID that I pass to this listener
                    if(globalData.approvedToggle == 1) then
                        storyboard.gotoScene("businessScene")
                    else
                        storyboard.gotoScene("locationScene")
                    end
                    display.getCurrentStage():setFocus( nil )
                    self.isFocus = false
                end
            end
        return true
    end
end

非常感谢任何有关此事的帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

我在我正在制作的Ecommerence应用程序上做了一段时间。我不是故事板的故事,但我记得使用这个API。如果我没记错的话,你需要使用event.target作为事件监听器并将所有内容传递给那里。我还记得你可以在display.loadRemoteImage API中嵌入一个函数,如下所示:

itemImage = display.loadRemoteImage(itemData.imageURL, "GET", 
            function(event)
               event.target.xScale = 0.4
               event.target.yScale = 0.4
               function openSite(event)
                   if event.phase == "ended" then
                      system.openURL( itemData.itemURL )
                   end
               end 
               event.target:addEventListener( "tap", openSite )
            end)

我的建议是删除所有故事板的内容,并尝试在不同的文档中使用API​​。我认为你需要简化它,这样你就不会感到困惑。

希望这有帮助。