It looks like you're new here. If you want to get involved, click one of these buttons!
URLLoader = Core.class(EventDispatcher) URLLoader.GET = "get" URLLoader.POST = "post" function URLLoader:init(url, variables) self.loader = UrlLoader.new() self.loader:addEventListener(Event.COMPLETE, self.onComplete, self) self.loader:addEventListener(Event.PROGRESS, self.onProgress, self) self.loader:addEventListener(Event.ERROR, self.onError, self) if url ~= nil then self:load(url, variables) end end function URLLoader:load(url, variables) local method = UrlLoader.GET local body = nil if variables ~= nil then if variables.method == URLLoader.GET then method = UrlLoader.GET if variables.data ~= nil then local get = {} for k,v in pairs(variables.data) do get[#get + 1] = k.."="..v end if #get ~= 0 then url = url.."?"..table.concat(get, "&") end end elseif variables.method == URLLoader.POST then method = UrlLoader.POST body = variables.data else error("Parameter 'method' must be one of the accepted values.") end end self.loader:load(url, method, body) end function URLLoader:close() self.loader:close() end function URLLoader:onComplete(event) self.data = event.data self:dispatchEvent(Event.new(Event.COMPLETE)) end function URLLoader:onProgress(event) local event2 = Event.new(Event.PROGRESS) event2.bytesLoaded = event.bytesLoaded event2.bytesTotal = event.bytesTotal self:dispatchEvent(event2) end function URLLoader:onError(event) self:dispatchEvent(Event.new(Event.ERROR)) end |
Likes: Janberka
Dislikes: mehmetuysal