FusePowered
×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2014.2524 | Released: 18 Dec 2014, 12:24pm | What's New | Download Now

object:toFront( )

Description:

Moves the target object to the visual front of its parent group (object.parent).

Syntax:

object:toFront()

Example:

The following sample creates a group of display objects (playing cards). Clicking on any one of the cards brings it to the top of the visual stack.

local cards = display.newGroup()     
 
function bringToFront( event )
        if event.phase == "began" then
           event.target:toFront() 
        end                         
        return true
end
 
for i=1,5 do
 
        local cardGroup = display.newGroup()
 
        -- Card outline
        local cardRect = display.newRoundedRect(0, 0, 125, 175, 12)
        cardRect.strokeWidth = 2
        cardRect:setFillColor(255, 255, 255)    
        cardRect:setStrokeColor(0,0,0, 75)                                        
        cardGroup:insert(cardRect)
 
        -- Card values
        local cardValue = display.newText(cardGroup, i, cardRect.contentWidth - 25, 0, native.systemFontBold, 24)     
        cardValue:setTextColor(255, 0, 0)
        local cardValue2 = display.newText(cardGroup, i, 0, cardRect.contentHeight - 40 , native.systemFontBold, 24)     
        cardValue2:setTextColor(255, 0, 0)       
 
        cardGroup.x = (i * 25)      
        
        cards:insert(cardGroup)
        
        cardGroup:addEventListener("touch", bringToFront)        
 
end

Parameters:

None.

Returns:

Nothing.

Remarks:
Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    Build 2010.243
  • Windows:
    Build 2010.243
  • iOS:
    Build 2010.243
  • Android:
    Build 2010.243

Replies

caprica13
User offline. Last seen 3 years 9 weeks ago. Offline
Joined: 17 Feb 2011

I have a group of display objects called menuScreen
(created with menuScreen = display.newGroup())

can I bring the whole group into the front at any point with menuScreen:toFront() ?

peach pellen
User offline. Last seen 2 years 4 days ago. Offline
Alumni
Joined: 12 Apr 2011

Hey Caprica,

Yes, that should work fine.

Peach :)

Nathan B
User offline. Last seen 1 day 16 hours ago. Offline
Joined: 18 Feb 2011

Can you use this to bring a widget button to the front?

ThinktankSocial
User offline. Last seen 38 weeks 2 days ago. Offline
Joined: 12 Jul 2011

not if ScrollView is involved because it seems to dominate all the things