Need help with Object.Children.item(x)

according to https://www.stardock.com/products/desktopx/help/dev_guide_3a_scripting.htm

DXScript has support for these object collections:
- DesktopX.Objects
- DesktopX.GroupObjects(“groupname”)
- Object.Children

They can be used like this:
- DesktopX.Objects.count – number of objects in the collection
- DesktopX.Objects.item(“obj1”) – returns the Object namespace of “obj1”
- DesktopX.Objects.item(3) – returns the Object namespace of the third object in the collection


Simply put the returned item is identical to the references returned by DesktopX.Object("name"), NOT DesktopX.ScriptObject("name"). You can always do DesktopX.ScriptObject(elem.name) if you need.  DesktopX.GroupObjects(“groupname”) and Object.Children collections work in a similar way.

 

so if DesktopX.Objects.item(3) works (and it does i have used it with success) then Object.Children.item(3) would work the same way right?

Sub Object_OnTimer1
 DesktopX.ScriptObject( Object.Children.item(activeIcon).name ).Animate(elapsedTime)  <<--- !! the issue i have in in this line !!
 
 elapsedTime = elapsedTime+1
 activeIcon = activeIcon+1

End Sub

i get the error

Object required: 'Object.Children.item(...)'
Line: 30
Code:
(not available)

 and i got the same error trying DesktopX.GroupObjects(“groupname”).item(X). However the code below using Object.Children works fine and is in the same script.

  For Each icon In Object.Children
   DesktopX.ScriptObject(icon.name).StartAnimation()
  Next
  SetTimer 1, frequency

anyone know what i have done wrong or how i could fix it?

14,347 views 2 replies
Reply #1 Top

Hi,

 

I think the problem is that you're treating desktopx.object.children as if it were a single object.

the desktopx.objects.item(3) relates to a specific object in the list of desktopx objects.

on the other hand,

desktopx.object("whatever the object name is").children refers to a group of objects that are children of the object.

so,

IF you want to reference a specific object from one of the children (lets say the third object or the object named "this one" you could reference it a couple of different ways-- I use for loops

for example (<----HA! get it?)

Dim obj

for each elem in desktopx.object("whatever the object name is").children

  if elem.name = "this one" then

     obj = elem

  end if

next

NOW you can reference whatever object you wanted to before using;

Sub Object_OnTimer1
 DesktopX.ScriptObject( obj.name ).Animate(elapsedTime)  <<--- !! the issue i have in in this line !!
 
 elapsedTime = elapsedTime+1
 activeIcon = activeIcon+1

End Sub

 

Pretty sure that will work, but if it doesn't, try first creating another variable and set it to obj.name (exaample:     variable = obj.name) and use that in place of obj.name in desktopx.scriptobject(variable).animate(elapsedtime)

(vbasic is pretty finicky about strings for some reason)

 

Hope that helps,

Homer

 

EDIT: forgot to mention: as far as I know, desktopx.object.children does not support the item system like desktopx.objects does.

Also, some properties of the variable "elem" in my for loop:

in this, elem acts as the object you're referencing-- meaning you can say anything after it that you can say after object. and you can apply things to it that will edit the object it refers to directly.

For efficiency, I recommend putting the for loop OUTSIDE of the timer subroutine, to avoid unnecessarily counting all children on each timer hit.

 

Good luck!

+1 Loading…
Reply #2 Top

Homer, with all this knowledge, I sure wish you'd put out some DX goodies for us. Maybe write a few plugins?

I can edit a little script, but man, this is way past me!  :thumbsup: