PDA

View Full Version : multiple "setvisible = false" how do I ....



teedee
02-06-2004, 09:32 AM
Hi,

Is it possible to easily (and quickly :D) 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 :D

TeeDee

Worm
02-06-2004, 10:38 AM
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

Lorne
02-06-2004, 11:37 AM
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.

teedee
02-06-2004, 11:40 AM
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 :D

Thanks

TeeDee

Lorne
02-06-2004, 11:49 AM
Here's a function that uses method 2 to do a set visible on all the buttons on the current page.


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:

-- show all buttons
AllButtons.SetVisible(true);

-- hide all buttons
AllButtons.SetVisible(false);

Lorne
02-06-2004, 11:57 AM
Here's an example of method 1:


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();

Lorne
02-06-2004, 12:10 PM
Here's a more advanced example that can handle different object types:


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);

teedee
02-06-2004, 05:33 PM
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

Lorne
02-09-2004, 09:04 AM
Here you go. Be sure to look in the following places:

Project > Global Functions
Page - On Preload
Button4 - On Click
Button5 - On Click

teedee
02-09-2004, 12:02 PM
Thank you so much :D

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

Thanks again

TeeDee