Fandom

Scratchpad

Segments: Scripting A Collection of Objects

215,884pages on
this wiki
Add New Page
Discuss this page0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.


Introduction

This article is for snippets of codes to control a collection of grouped objects (groups, children) or control a collection of ungrouped objects. All scripts below should go in a separate object which you will use to control the collection of objects.


Control Groups, Children

Toggle a group

Sub Object_OnLbuttonUp(x,y,dragged)
	If Not dragged Then 
		For Each elem In Desktopx.GroupObjects("testgroup")
			If elem.visible = True Then 
				elem.visible = False
			ElseIf elem.visible = False Then 
				elem.visible = True
			End If
		Next
	End If
End Sub


Toggle child objects

Sub Object_OnLbuttonUp(x,y,dragged)
	If Not dragged Then 
		For Each elem In Desktopx.Object(“Parentobject”).Children
			If elem.visible = True Then 
				elem.visible = False
			ElseIf elem.visible = False Then 
				elem.visible = True
			End If
		Next
	End If
End Sub

Move a group

Sub Object_OnLbuttonUp(x,y,dragged)
	If Not dragged Then 
		For Each elem In Desktopx.GroupObjects("testgroup")
			elem.left = elem.left + 2
		Next
	End If
End Sub

Move child objects

Sub Object_OnLbuttonUp(x,y,dragged)
	If Not dragged Then 
		For Each elem In Desktopx. Object("Parentobject").children
			elem.left = elem.left + 2
		Next
	End If
End Sub



Control a Collection of ungrouped objects

Method 1- Listing each object

Toggle objects

Sub Object_OnLbuttonUp(x,y,dragged)
	If Not dragged Then 
		‘To identify if the objects are already showing or hidden
‘ we check the visibility of one of them
		Select Case Desktopx.Object("1").visible 
			Case True
				showhide= False
			Case False
				showhide= True
		End Select
		'Set objects visibility
		Desktopx.Object("1").visible = showhide
		Desktopx.Object("2").visible = showhide
		Desktopx.Object("3").visible = showhide
	End If
End Sub


Move objects

Sub Object_OnLbuttonUp(x,y,dragged)
	If Not dragged Then 
		Desktopx.Object("1").top = Desktopx.Object("1").top + 2
		Desktopx.Object("2").top = Desktopx.Object("2").top + 2
		Desktopx.Object("3").top = Desktopx.Object("3").top + 2
	End If
End Sub


Method2- Using serialized names

For this method, rename your collection of objects like this- object1, object2, object3 etc. (Use any name you like but make sure they all have the same name and are numbered sequentially (1,2,3, NOT 01, 02, 03). Insert the scripts below into the controller object making adjustments to the name of the objects and the number of objects you are controlling.

Toggle objects

Dim numofobjs
'Define number of objects to control
numofobjs = 3

Sub Object_OnLbuttonUp(x,y,dragged)
	If Not dragged Then toggle
End Sub

Function toggle
	'Check the visiblity of one of the objects
	Select Case Desktopx.Object("object1").visible 
			Case True
				showhide= False
			Case False
				showhide= True
	End Select
	'Reset visibility of objects
	For x= 1 To numofobjs
        ‘-Write everything except the number in the object name, the x will take care of that
		desktopx.Object("object" & x).visible =showhide 
	Next
End Function


Move objects

Dim numofobjs
'Define number of objects to control
numofobjs = 3

Sub Object_OnLbuttonUp(x,y,dragged)
	If Not dragged Then move
End Sub

Function move
	For x= 1 To numofobjs
‘-Write everything except the number in the object name, the x will take care of that
		desktopx.Object("object" & x).left = desktopx.Object("object" & x).left + 2 
	Next
End Function

Comments/Suggestions

None right now.

--SViz 23:59, 6 January 2007 (UTC)

Also on Fandom

Random wikia