Thank you Rob! I attached my programs hoping you can help me. Observe file view1 and view2 are identical. Best regards
–
– main.lua
–
– include Corona’s “widget” library
local widget = require “widget”
local composer = require “composer”
– show default status bar
display.setStatusBar( display.DefaultStatusBar )
display.setDefault(“background”, 1, 1, 1)
– event listeners for tab buttons:
local function onZeroView( event )
composer.gotoScene( “view0” )
end
local function onFirstView( event )
composer.gotoScene( “view1” )
end
local function onSecondView( event )
composer.gotoScene( “view2” )
end
– create a tabBar widget with two buttons at the bottom of the screen
– table to setup buttons
local tabButtons = {
{ defaultFile=“button1.png”, overFile=“button1-down.png”, width = 32, height = 32, onPress=onZeroView },
{ defaultFile=“chisiamo.png”, overFile=“chisiamo.png”, width = 32, height = 32, onPress=onFirstView },
{ defaultFile=“galleria.png”, overFile=“galleria.png”, width = 32, height = 32, onPress=onSecondView },
}
– create the tabBar widget
local tabBar = widget.newTabBar{
top = display.contentHeight - 40, – 50 is default height for tabBar widget
buttons = tabButtons
}
– function for files copy
local function copyFile( srcName, srcPath, dstName, dstPath )
local results = false
– Copy the source file to the destination file
local rFilePath = system.pathForFile( srcName, srcPath )
local wFilePath = system.pathForFile( dstName, dstPath )
local rfh = io.open( rFilePath, “rb” )
local wfh, errorString = io.open( wFilePath, “wb” )
if not ( wfh ) then
– Error occurred; output the cause
print( "File error: " … errorString )
return false
else
– Read the file and write to the destination directory
local data = rfh:read( “*a” )
if not ( data ) then
print( “Read error!” )
return false
else
if not ( wfh:write( data ) ) then
print( “Write error!” )
return false
end
end
end
results = 2 – 2 = File copied successfully!
– Close file handles
rfh:close()
wfh:close()
return results
end
– Copy my HTML files (in zip format) from from “system.ResourceDirectory” to “system.DocumentsDirectory”
copyFile( “chisiamo.zip”, system.ResourceDirectory, “chisiamo.zip”, system.DocumentDirectory )
copyFile( “galleria.zip”, system.ResourceDirectory, “galleria.zip”, system.DocumentDirectory )
– Handle back button
function onKeyback( event )
if event.keyName == “back” then
if not ( wbeView == nil ) and webView.canGoBack then
webView:back()
print(“go back eseguito”)
composer.removeHidden()
end
end
return true
end
– Handle onKeyBack
Runtime:addEventListener( “key”, onKeyback )
– Open the App
onZeroView() – invoke first tab button’s onPress event manually
–
– view1.lua
–
– include Corona’s “widget” library
local composer = require( “composer” )
local scene = composer.newScene()
– set default home page on the screen
function scene:create( event )
local sceneGroup = self.view
local image = display.newImage( “postermostra.jpg” )
image.width = display.contentWidth * 0.9
image.height = ( display.contentHeight - 40) * 0.9
image.x = display.contentCenterX
image.y = (display.contentCenterY - 40)
sceneGroup:insert( image )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == “will” then
– composer.removeHidden()
– Called when the scene is still off screen and is about to move on screen
elseif phase == “did” then
– Called when the scene is now on screen
–
– INSERT code here to make the scene come alive
– e.g. start timers, begin animation, play audio, etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == “will” then
– Called when the scene is on screen and is about to move off screen
–
– INSERT code here to pause the scene
– e.g. stop timers, stop animation, unload sounds, etc.)
if webView and webView.removeSelf then
webView:removeSelf()
webView = nil
end
elseif phase == “did” then
– Called when the scene is now off screen
end
end
function scene:destroy( event )
local sceneGroup = self.view
– Called prior to the removal of scene’s “view” (sceneGroup)
–
– INSERT code here to cleanup the scene
– e.g. remove display objects, remove touch listeners, save state, etc.
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
–
– view1.lua
– view2.lua
–
local composer = require( “composer” )
local scene = composer.newScene()
local webView = native.newWebView( display.contentCenterX, display.contentCenterY - 10, display.contentWidth, display.contentHeight - 90)
local widget = require( “widget” )
local bkButton = nil
– Set command line depending OS
if ( system.getInfo( “platform”) == “android” ) then
bkButton = widget.newButton(
{
width = display.contentWidth,
height = 30,
left = 0,
top = 0,
defaultFile = “testata-android.png”,
onEvent = onbkButton,
}
)
else
bkButton = widget.newButton(
{
width = display.contentWidth,
height = 30,
left = 0,
top = 0,
defaultFile = “testata-ios.png”,
onEvent = onbkButton,
}
)
end
– back command on webView
function onbkButton( event )
if event.phase == “began” then
if not ( wbeView == nil ) and webView.canGoBack then
webView:back()
composer.removeHidden()
end
end
end
function scene:create( event )
local sceneGroup = self.view
webView:request( “http://www.coronalabs.com/” )
– webView:request( “chisiamo/chisiamo.html”, system.DocumentDirectory )
sceneGroup:insert( webView )
sceneGroup:insert( bkButton )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == “will” then
– Called when the scene is still off screen and is about to move on screen
composer.removeHidden()
elseif phase == “did” then
– Called when the scene is now on screen
–
– INSERT code here to make the scene come alive
– e.g. start timers, begin animation, play audio, etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
composer.removeHidden()
if event.phase == “will” then
– Called when the scene is on screen and is about to move off screen
–
– INSERT code here to pause the scene
– e.g. stop timers, stop animation, unload sounds, etc.)
if webView and webView.removeSelf then
webView:removeSelf()
webView = nil
bkButton:removeSelf()
bkButton = nil
end
elseif phase == “did” then
– Called when the scene is now off screen
composer.hideOverlay()
end
end
function scene:destroy( event )
local sceneGroup = self.view
– Called prior to the removal of scene’s “view” (sceneGroup)
–
– INSERT code here to cleanup the scene
– e.g. remove display objects, remove touch listeners, save state, etc.
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
–scene:addEventListener( “destroy”, scene )
return scene
– view1.lua
– view2.lua