Close button help

4 replies [Last post]
david.newman
User offline. Last seen 1 year 47 weeks ago. Offline
Joined: 6 Sep 2011

So first, let me say I am a.net programmer trying to make it in a lua world. So dont judge me too harshly when I show code snippets ;)

However, I am making an interface for this hospital app I am working on that pops up a map an a text box underneath with the directions to the hospital. (This was per request fyi). So I got that no problem, however IM trying to make a little X button down on the corner of the text box that will close the map and text box, because the are over laying the home screen of the app. How can I do this? I tried using widget buttons and touch events on an image but something is just not working.

Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
local function ongMap( event )
 
 
local obj = display.newImage( "closeButton.jpg" , -100, 250 )
        obj.width = 25
        obj.height = 25
-- touch listener
function obj:touch( event )
--do something? I cant get anything to work here, tried multiple functions ----
end
 
-- begin detecting touches
obj:addEventListener( "touch", obj )
 
myMap = native.newMapView( 25, 0, 275, 180 )
myMap.mapType = "hybrid" -- other mapType options are "satellite" or "hybrid"
myMap.isScrollEnabled = true
myMap.isZoomEnabled = true 
myMap.isLocationUpdating = true
isVisible = myMap.isLocationVisible
myMap:setCenter( 38.354614, -81.726351 )
myMap:addMarker(  38.354614, -81.726351)
-- Adding the Text Box that contains the Directions
local textBox = native.newTextBox( 22, 183, 280, 225 )
textBox.text = "Boring directions, blah...blah...blah..."
local group = display.newGroup()
group:insert( obj )
 
end

Replies

nick_sherman
User offline. Last seen 22 hours 21 min ago. Offline
Joined: 23 Sep 2011

Something like this should get you started:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
local function ongMap( event )
 
        local obj = display.newImageRect( "closeButton.jpg" ,25,25 )
                obj.x = 60
                obj.y = 300     -- replaced with newImageRect for dynamic scaling (adjust X & Y as required)
 
        obj.touch = function (event)
        
                local btn = event.target
 
                if event.phase == "ended" then 
 
                        btn.alpha = 0  -- example to show the function doing something
                end
        end
 
        -- begin detecting touches
        obj:addEventListener( "touch", obj.touch)
 
        myMap = native.newMapView( 25, 0, 275, 180 )
        myMap.mapType = "hybrid" -- other mapType options are "satellite" or "hybrid"
        myMap.isScrollEnabled = true
        myMap.isZoomEnabled = true 
        myMap.isLocationUpdating = true
        isVisible = myMap.isLocationVisible
        myMap:setCenter( 38.354614, -81.726351 )
        myMap:addMarker(  38.354614, -81.726351)
        -- Adding the Text Box that contains the Directions
        local textBox = native.newTextBox( 22, 183, 280, 225 )
        textBox.text = "Boring directions, blah...blah...blah..."
        local group = display.newGroup()
        group:insert( obj )
 
end 

david.newman
User offline. Last seen 1 year 47 weeks ago. Offline
Joined: 6 Sep 2011

Should I replace btn.alpha = 0  -- example to show the function doing something with something like:

       storyboard.purgeScene()

-or even -

1
2
3
        scene:destroyScene( event )
        local group = self.view
        display.remove( button )

Or just leave it as is?

david.newman
User offline. Last seen 1 year 47 weeks ago. Offline
Joined: 6 Sep 2011

well I tried that plus other functions to get the map to close. I just can not get the map and textbox to close. The button now closes but thats about it.

david.newman
User offline. Last seen 1 year 47 weeks ago. Offline
Joined: 6 Sep 2011

Still searching. Willing to pay for help if anyone wants to jump on it. I find the lack of documentation about this disturbing. I have tried numerous functions and just can not get it to work. The map nor text box will not close.

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.