Andromo - Start Making Apps - Free Signup

Announcement

Collapse
No announcement yet.

Function: Show/Hide All Objects of a Specific Type

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Function: Show/Hide All Objects of a Specific Type

    This function will show or hide all objects of a certain type on a page with just one call.

    Code:
    -- Name: ShowHideObjectsOfType
    -- Purpose: To show or hide all objects of a certain type on a page
    -- Arguments:
    --		Type - (number) The type of object to work on.  For a list of
    --						type constants, see the help file for Page.GetObjectType
    --		Show - (boolean) Whether to show (true) or hide (false) the object
    -- Returns: Nothing
    function ShowHideObjectsOfType(Type, Show)
    	local tblObjects = Page.EnumerateObjects();
    	if tblObjects then
    		for i,ObName in tblObjects do
    			nTypeCurrent = Page.GetObjectType(ObName);
    			if(nTypeCurrent == Type)then
    				-- Matches the type we are looking for...
    				if(nTypeCurrent == OBJECT_BUTTON)then
    					Button.SetVisible(ObName,Show);
    				elseif(nTypeCurrent == OBJECT_LABEL)then
    					Label.SetVisible(ObName,Show);
    				elseif(nTypeCurrent == OBJECT_PARAGRAPH)then
    					Paragraph.SetVisible(ObName,Show);
    				elseif(nTypeCurrent == OBJECT_IMAGE)then
    					Image.SetVisible(ObName,Show);
    				elseif(nTypeCurrent == OBJECT_FLASH)then
    					Flash.SetVisible(ObName,Show);
    				elseif(nTypeCurrent == OBJECT_VIDEO)then
    					Video.SetVisible(ObName,Show);
    				elseif(nTypeCurrent == OBJECT_WEB)then
    					Web.SetVisible(ObName,Show);
    				elseif(nTypeCurrent == OBJECT_INPUT)then
    					Input.SetVisible(ObName,Show);
    				elseif(nTypeCurrent == OBJECT_HOTSPOT)then
    					-- Not applicable - do nothing
    				elseif(nTypeCurrent == OBJECT_LISTBOX)then
    					ListBox.SetVisible(ObName,Show);
    				elseif(nTypeCurrent == OBJECT_PLUGIN)then
    					Plugin.SetVisible(ObName,Show);
    				end
    			end
    		end
    	else
    		-- Error
    		Dialog.Message("Error", "Failed to enumerate objects: ".._tblErrorMessages[Application.GetLastError()]);
    	end
    end
    This code could easily be adjusted to apply any kind of action to objects on a page without knowing anything specific about the page you are working on. For example, to enable or disable objects or to change an object type's text.

    Attached is a sample project that shows the code in use. The function is located in the Global Functions script.
    Attached Files
Working...
X