Game Development Reference
In-Depth Information
To open a web page, you can use the following:
application:openUrl(" http://www.oz-apps.com " )
To send an e-mail, you can use this:
application:openUrl("mailto: dev.ozapps@gmail.com ")
You can also add a subject and message as follows:
application:openUrl("mailto: dev.ozapps@gmail.com?subject=Hello Gideros&body=This is a test ")
If you running the app on the iPhone, then you can also dial a number by using the following:
application:openUrl("tel:555-7827-9277")
In a game, you might want to download a file, some JSON, or a text file containing some level data.
This cannot be achieved with the openUrl function. We can, however, use the UrlLoader class.
Here's an example:
local loader = UrlLoader.new(" http://example.com/image.png ")
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)
In this code, we first create a new instance of UrlLoader , which will start the download. The default
is method for UrlLoader is UrlLoader.GET . The other options are POST , PUT , and DELETE . When using
POST or PUT , headers and data can be passed to the URL.
local url = " http://www.[yourDomain].com/application.php?userid=gideros&login=guest "
local loader1 = UrlLoader.new(url)
local loader2 = UrlLoader.new(url, UrlLoader.GET) -- Same as the previous line
Search WWH ::




Custom Search