Button Android

Hi I use it:

 system.openURL( "http://www.google.com" )

here:

if clickedButton == g\_rateButton then

but it don’t work.Who can help me? Please

You will need to post more code.  Where do you setup your button? What does your entire button handler look like?

Rob

​g\_rateButton = nil g\_playButton = nil g\_rankButton = nil local clickedButton = nil local function checkMenuButton(button, name, point) &nbsp; &nbsp; cclog("checkMenuButton : "..name) &nbsp; &nbsp; local buttonSize = getSpriteSize(name) &nbsp; &nbsp; local buttonX = button:getPositionX() &nbsp; &nbsp; local buttonY = button:getPositionY() &nbsp; &nbsp; if math.abs(point.x - buttonX) \< buttonSize.width / 2 and&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; math.abs(point.y - buttonY) \< buttonSize.height / 2 then &nbsp; &nbsp; &nbsp; &nbsp; clickedButton = button &nbsp; &nbsp; &nbsp; &nbsp; return true &nbsp; &nbsp; end &nbsp; &nbsp; return false end -- listener local touchBeginPoint = nil function onCommonMenuLayerTouchBegan(touch, event) &nbsp; &nbsp; local location = touch:getLocation() &nbsp; &nbsp; cclog("onCommonMenuLayerTouchBegan: %0.2f, %0.2f", location.x, location.y) &nbsp; &nbsp; touchBeginPoint = {x = location.x, y = location.y} &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if g\_rateButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; checkMenuButton(g\_rateButton, "button\_rate", touchBeginPoint) &nbsp; &nbsp; end &nbsp; &nbsp; if g\_playButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; checkMenuButton(g\_playButton, "button\_play", touchBeginPoint) &nbsp; &nbsp; end &nbsp; &nbsp; if g\_rankButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; checkMenuButton(g\_rankButton, "button\_score", touchBeginPoint)&nbsp; &nbsp; &nbsp; end &nbsp;&nbsp; &nbsp; &nbsp; if g\_plusButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; checkMenuButton(g\_plusButton, "plus", touchBeginPoint)&nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if clickedButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; clickedButton:setPosition(cc.p(clickedButton:getPositionX(), clickedButton:getPositionY() - 3)) &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp;-- CCTOUCHBEGAN event must return true &nbsp; &nbsp; return true end function onCommonMenuLayerTouchEnded(touch, event) &nbsp; &nbsp; local location = touch:getLocation() &nbsp; &nbsp; cclog("onCommonMenuLayerTouchEnded: %0.2f, %0.2f", location.x, location.y) &nbsp; &nbsp; touchBeginPoint = nil &nbsp; &nbsp; if clickedButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; clickedButton:setPosition(cc.p(clickedButton:getPositionX(), clickedButton:getPositionY() + 3)) &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if clickedButton == g\_rateButton then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;system.openURL("http://google.com") &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; elseif clickedButton == g\_playButton then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local gameScene = nil&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if g\_initFlag == nil then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gameScene = require("scripts.GameScene") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gameScene = createGameScene() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local trans = cc.TransitionFade:create(0.5, gameScene, cc.c3b(0,0,0)) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cc.Director:getInstance():replaceScene(trans) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cc.SimpleAudioEngine:getInstance():playEffect(uiPath) &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif clickedButton == g\_rankButton then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showAds() &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; clickedButton = nil &nbsp; &nbsp; end end

I don’t know what this cc.* library is or what it does.   I can’t really help too much.  I’m guessing that **if** your checkMenuButton() function actually gets those parameters (most implementations of Corona touch handlers don’t pass in extra parameters beyond their event table), that you would want to do something like:

if name == "button\_rate" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; system.openURL("http://www.google.com") elseif name == "button\_play" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- do whatever you want that button to do. elseif name == "button\_somethingelse" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- do more things end

However you should look at the Corona SDK native.showPopup() API call.  We have functions that let you bring up the store’s ratings and reviews page.   See:  http://docs.coronalabs.com/api/library/native/showPopup.html#appstore

Rob

You will need to post more code.  Where do you setup your button? What does your entire button handler look like?

Rob

​g\_rateButton = nil g\_playButton = nil g\_rankButton = nil local clickedButton = nil local function checkMenuButton(button, name, point) &nbsp; &nbsp; cclog("checkMenuButton : "..name) &nbsp; &nbsp; local buttonSize = getSpriteSize(name) &nbsp; &nbsp; local buttonX = button:getPositionX() &nbsp; &nbsp; local buttonY = button:getPositionY() &nbsp; &nbsp; if math.abs(point.x - buttonX) \< buttonSize.width / 2 and&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; math.abs(point.y - buttonY) \< buttonSize.height / 2 then &nbsp; &nbsp; &nbsp; &nbsp; clickedButton = button &nbsp; &nbsp; &nbsp; &nbsp; return true &nbsp; &nbsp; end &nbsp; &nbsp; return false end -- listener local touchBeginPoint = nil function onCommonMenuLayerTouchBegan(touch, event) &nbsp; &nbsp; local location = touch:getLocation() &nbsp; &nbsp; cclog("onCommonMenuLayerTouchBegan: %0.2f, %0.2f", location.x, location.y) &nbsp; &nbsp; touchBeginPoint = {x = location.x, y = location.y} &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if g\_rateButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; checkMenuButton(g\_rateButton, "button\_rate", touchBeginPoint) &nbsp; &nbsp; end &nbsp; &nbsp; if g\_playButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; checkMenuButton(g\_playButton, "button\_play", touchBeginPoint) &nbsp; &nbsp; end &nbsp; &nbsp; if g\_rankButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; checkMenuButton(g\_rankButton, "button\_score", touchBeginPoint)&nbsp; &nbsp; &nbsp; end &nbsp;&nbsp; &nbsp; &nbsp; if g\_plusButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; checkMenuButton(g\_plusButton, "plus", touchBeginPoint)&nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if clickedButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; clickedButton:setPosition(cc.p(clickedButton:getPositionX(), clickedButton:getPositionY() - 3)) &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp;-- CCTOUCHBEGAN event must return true &nbsp; &nbsp; return true end function onCommonMenuLayerTouchEnded(touch, event) &nbsp; &nbsp; local location = touch:getLocation() &nbsp; &nbsp; cclog("onCommonMenuLayerTouchEnded: %0.2f, %0.2f", location.x, location.y) &nbsp; &nbsp; touchBeginPoint = nil &nbsp; &nbsp; if clickedButton ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; clickedButton:setPosition(cc.p(clickedButton:getPositionX(), clickedButton:getPositionY() + 3)) &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if clickedButton == g\_rateButton then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;system.openURL("http://google.com") &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; elseif clickedButton == g\_playButton then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local gameScene = nil&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if g\_initFlag == nil then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gameScene = require("scripts.GameScene") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gameScene = createGameScene() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local trans = cc.TransitionFade:create(0.5, gameScene, cc.c3b(0,0,0)) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cc.Director:getInstance():replaceScene(trans) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cc.SimpleAudioEngine:getInstance():playEffect(uiPath) &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif clickedButton == g\_rankButton then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showAds() &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; clickedButton = nil &nbsp; &nbsp; end end

I don’t know what this cc.* library is or what it does.   I can’t really help too much.  I’m guessing that **if** your checkMenuButton() function actually gets those parameters (most implementations of Corona touch handlers don’t pass in extra parameters beyond their event table), that you would want to do something like:

if name == "button\_rate" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; system.openURL("http://www.google.com") elseif name == "button\_play" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- do whatever you want that button to do. elseif name == "button\_somethingelse" then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- do more things end

However you should look at the Corona SDK native.showPopup() API call.  We have functions that let you bring up the store’s ratings and reviews page.   See:  http://docs.coronalabs.com/api/library/native/showPopup.html#appstore

Rob