multiple "setvisible = false" how do I ....

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • teedee
    Forum Member
    • Feb 2004
    • 11

    multiple "setvisible = false" how do I ....

    Hi,

    Is it possible to easily (and quickly ) set multiple "setvisible = false" actions to a button.

    I require that each of 10 buttons sets "setvisable = false" to 8 - 10 buttons on a page whilst similtainiously (sp) setting "setvisable = true" to another range of 8 - 10 buttons

    Looking for a way to do this without adding each action individually and cutting down on the actual code required to perform these action.

    Thanks again

    TeeDee
  • Worm
    Indigo Rose Customer
    • Jul 2002
    • 3967

    #2
    What I've done in the past is have each button end with a Numeric Value, like Button1 , Button2

    then use a for loop, concatate the loop variable to your button name.

    Add 10 buttons to a page leaving the buttons named Button1 through Button10. Set the visible property on some of them to false.

    Then use this code to swap the hidden buttons with the visible ones:

    for n=1, 10 do
    --hide all visible buttons and show all hidden
    Button.SetVisible("Button"..n,not Button.IsVisible("Button"..n))
    end

    Comment

    • Lorne
      Indigo Rose Staff Member
      • Feb 2001
      • 2729

      #3
      If you don't want to name your objects that way, there are two other methods you can use.

      1. Create a table containing the names of the objects you want to modify, and then use a for loop to walk through the table, showing or hiding all the objects in the list.

      2. Use Page.EnumerateObjects and Page.GetObjectType to operate on all the objects of a given type (e.g. all the buttons) on the page.

      Use method 1 if you don't want to modify all of the objects of that type on the page (e.g. you want to modify 8 out of 12 button objects). Use method 2 if you don't want to have to update the table whenever you add objects to the page or rename them.
      --[[ Indigo Rose Software Developer ]]

      Comment

      • teedee
        Forum Member
        • Feb 2004
        • 11

        #4
        Originally posted by Lorne
        1. Create a table containing the names of the objects you want to modify, and then use a for loop to walk through the table, showing or hiding all the objects in the list.
        That sounds more like I need, can you elaborate a little bit more how to do this, 1st time for me and I am reying to learn all this

        Thanks

        TeeDee

        Comment

        • Lorne
          Indigo Rose Staff Member
          • Feb 2001
          • 2729

          #5
          Here's a function that uses method 2 to do a set visible on all the buttons on the current page.

          Code:
          AllButtons = {};
          function AllButtons.SetVisible(bVisible)
          	local tbObjects = Page.EnumerateObjects();
          	for index, name in tbObjects do
          		if Page.GetObjectType(name) == OBJECT_BUTTON then
          			Button.SetVisible(name,bVisible);
          		end
          	end	
          end
          Here's an example of calling that function:
          Code:
          -- show all buttons
          AllButtons.SetVisible(true);
          
          -- hide all buttons
          AllButtons.SetVisible(false);
          --[[ Indigo Rose Software Developer ]]

          Comment

          • Lorne
            Indigo Rose Staff Member
            • Feb 2001
            • 2729

            #6
            Here's an example of method 1:

            Code:
            MyButtons = {"Button1","Button2","Button3"};
            function HideMyButtons()
            	for index, name in MyButtons do
            		Button.SetVisible(name,false);
            	end
            end
            
            function ShowMyButtons()
            	for index, name in MyButtons do
            		Button.SetVisible(name,true);
            	end
            end
            
            -- hide the buttons listed in the 'MyButtons' table
            HideMyButtons();
            --[[ Indigo Rose Software Developer ]]

            Comment

            • Lorne
              Indigo Rose Staff Member
              • Feb 2001
              • 2729

              #7
              Here's a more advanced example that can handle different object types:

              Code:
              Objects = {};
              function Objects.SetVisible(tbObjectNames, bVisible)
              	for index, name in tbObjectNames do
              		local obtype = Page.GetObjectType(name);
              		if obtype == OBJECT_BUTTON then
              			Button.SetVisible(name, bVisible);
              		elseif obtype == OBJECT_FLASH then
              			Flash.SetVisible(name, bVisible);
              		elseif obtype == OBJECT_IMAGE then
              			Image.SetVisible(name, bVisible);
              		elseif obtype == OBJECT_INPUT then
              			Input.SetVisible(name, bVisible);
              		elseif obtype == OBJECT_LABEL then
              			Label.SetVisible(name, bVisible);
              		elseif obtype == OBJECT_LISTBOX then
              			ListBox.SetVisible(name, bVisible);
              		elseif obtype == OBJECT_PARAGRAPH then
              			Paragraph.SetVisible(name, bVisible);
              		elseif obtype == OBJECT_PLUGIN then
              			Plugin.SetVisible(name, bVisible);
              		elseif obtype == OBJECT_VIDEO then
              			Video.SetVisible(name, bVisible);
              		elseif obtype == OBJECT_WEB then
              			Web.SetVisible(name, bVisible);
              		else
              			Debug.Print("Error: "..name.." - Invalid object type.");
              		end
              	end
              end
              
              -- hide Button1, Button2 and Label5
              MyObjects = {"Button1","Button2","Label5"};
              Objects.SetVisible(MyObjects, false);
              --[[ Indigo Rose Software Developer ]]

              Comment

              • teedee
                Forum Member
                • Feb 2004
                • 11

                #8
                thanks, still trying to get my head around this so I can understand it.........

                any chance you could throw together a couple of working examples so I can see where the code goes (can't even seem to get that right :( )and what happems when I modify it ?

                Thanks again, I appreciiate the help.

                TeeDee

                Comment

                • Lorne
                  Indigo Rose Staff Member
                  • Feb 2001
                  • 2729

                  #9
                  Here you go. Be sure to look in the following places:

                  Project > Global Functions
                  Page - On Preload
                  Button4 - On Click
                  Button5 - On Click
                  Attached Files
                  --[[ Indigo Rose Software Developer ]]

                  Comment

                  • teedee
                    Forum Member
                    • Feb 2004
                    • 11

                    #10
                    Thank you so much

                    I find it so much easier to learn playing with a working version and then brealing it to suit my needs

                    Thanks again

                    TeeDee

                    Comment

                    Working...
                    X