how to close or destroy a admob ad on screen change ?

Hi how can i close or destroy a “admob” ad on screen change ? its staying on the screen even if i go to a other .lua file ?

-- Create a text object to display ad status local screenGroup = self.view local statusText = display.newText( "", 0, 0, native.systemFontBold, 22 ) statusText:setTextColor( 255 ) statusText:setReferencePoint( display.CenterReferencePoint ) statusText.x, statusText.y = display.contentWidth \* 0.5, 160 local showAd -- Set up ad listener. local function adListener( event ) -- event table includes: -- event.provider -- event.isError (e.g. true/false ) local msg = event.response -- just a quick debug message to check what response we got from the library print("Message received from the ads library: ", msg) if event.isError then statusText:setTextColor( 255, 0, 0 ) statusText.text = "Error Loading Ad" statusText.x = display.contentWidth \* 0.5 local screenGroup = self.view showAd( "banner" ) else --efter add end end -- Initialize the 'ads' library with the provider you wish to use. if appID then ads.init( provider, appID, adListener ) end -------------------------------------------------------------------------------- -- UI -------------------------------------------------------------------------------- -- initial variables local sysModel = system.getInfo("model") local sysEnv = system.getInfo("environment") -- Shows a specific type of ad showAd = function( adType ) local screenGroup = self.view local adX, adY = display.screenOriginX, 400 statusText.text = "" ads.show( adType, { x=adX, y=adY } ) end -- if on simulator, let user know they must build for device if sysEnv == "simulator" then else local screenGroup = self.view -- start with banner ad showAd( "banner" ) end

-Kevin

Hi Kevin,

Please explore the “ads.hide()” API:

http://docs.coronalabs.com/api/library/ads/hide.html

Hi Brent,

The “ads.hide()” API is not working for me adding it to the “exitScene” messes up the whole app

Hi Kevin,

Can you be more specific on the error this is causing?

Hi Brent,

when i use the above code in my main.lua file it displays the ad as i want it to be but when i add  “ads.hide()” (as the ad stay on every scene)  in the “exitScene” scene section i get this error in the terminal " attempt to index global ‘ads’ (a nil value)" which i understand as the ads don’t display in the simulator but when i open the app op my phone (galaxy s4) non of the buttons respond, and it just stay on the main.lua file/scene

are you doing an:

local ads = require “ads”

at the top of your scene file?

@rob

yes 

local provider = "admob" local appID = "\*\*\*\*\*\*\*\*\*\*" local ads = require "ads"

:smiley:

changed showAd( “banner” ) to ads.show( “banner” ,{x=display.screenOriginX, y=400}) now it works

Hi Kevin,

Please explore the “ads.hide()” API:

http://docs.coronalabs.com/api/library/ads/hide.html

Hi Brent,

The “ads.hide()” API is not working for me adding it to the “exitScene” messes up the whole app

Hi Kevin,

Can you be more specific on the error this is causing?

Hi Brent,

when i use the above code in my main.lua file it displays the ad as i want it to be but when i add  “ads.hide()” (as the ad stay on every scene)  in the “exitScene” scene section i get this error in the terminal " attempt to index global ‘ads’ (a nil value)" which i understand as the ads don’t display in the simulator but when i open the app op my phone (galaxy s4) non of the buttons respond, and it just stay on the main.lua file/scene

are you doing an:

local ads = require “ads”

at the top of your scene file?

@rob

yes 

local provider = "admob" local appID = "\*\*\*\*\*\*\*\*\*\*" local ads = require "ads"

:smiley:

changed showAd( “banner” ) to ads.show( “banner” ,{x=display.screenOriginX, y=400}) now it works