adding mute function when object is hidden
Sunday, February 25, 2007 by warreni | Discussion: DesktopX
I'm trying to modify (for personal use) the script in ickypoo's Marvin widget to add a function where the sound is automatically muted when the widget is hidden. I think I know how to do this (I've been reading the DesktopX scripting tutorial), but what I'm doing is not working. Actually, I've tried several different paths to achieve this, including using ObjectOnStateChange calls to detect whether the object is hidden or shown. This is what the latest iteration of modification looks like:
Object.PersistStorage("soundNUM") = 1
'Called when the script is executed
Sub Object_OnScriptEnter
Object.SetTimer 99384, 25
Object.SetTimer 98994, 60000
End Sub
'Called when the script is terminated
Sub Object_OnTimer99384
Object.Left = Object.Left + 1
If Object.Left > System.ScreenWidth Then Object.Left = - Object.Width
End Sub
Sub Object_OnTimer98994
Object_OnMouseEnter()
Object_OnShow(IsVisible)
End Sub
Sub Object_OnShow(IsVisible)
If IsVisible = True Then
Object.Volume = 85
Else
Object.Volume = 0
End If
End Sub
Sub Object_OnMouseEnter
Object.ToolTipText = "Playing marvin" & Object.PersistStorage("soundNUM") & ".wav"
Object.Sound = "marvin" & Object.PersistStorage("soundNUM") & ".wav"
Object.PersistStorage("soundNUM") = Object.PersistStorage("soundNUM") + 1
If Object.PersistStorage("soundNUM") > 16 Then Object.PersistStorage("soundNUM") = 1
End Sub
Could someone here who's really clever with scripting give me a pointer or two? I've just started trying to tinker with this, and I may be overlooking something dumb. Thanks.
Reply #2 Monday, March 5, 2007 8:02 AM
First of all you need rename the "Mouse away" state to "silent" add one more state "sound" into the Marvin. Then:
1. Copy the "marvin.ani.PNG" from "silent" to "sound" and apply the same animation.
2. Remove the "marvin6.wav" file from the "silent" state and paste it to the "sound" state.
3. Create new text object "test" on the desktop.
Paste this code into the Marvin:
Dim lborder,rborder
'Called when the script is executed
Sub Object_OnScriptEnter
lborder = -1
rborder = -1
Object.state = "silent"
Object.PersistStorage("soundNUM") = 0
object.left = System.VscreenLeft - Object.width * 2
Object.SetTimer 1, 25
Object.SetTimer 2, 60000
End Sub
'Called when the script is terminated
Sub Object_OnTimer1
lborder = Object.right - System.VscreenLeft
rborder = System.ScreenWidth - Object.right
If lborder = 0 Then
Object.state = "sound"
Object.PersistStorage("soundNUM") = 6
Object.Sound = "marvin" & Object.PersistStorage("soundNUM") & ".wav"
End If
If rborder = 0 Then
Object.PersistStorage("soundNUM") = 7
Object.Sound = "marvin" & Object.PersistStorage("soundNUM") & ".wav"
'Object.state = "silent"
End If
'
desktopx.object("test").text = "left="&lborder&vblf&"right="&rborder&vblf&"sound="&Object.PersistStorage("soundNUM") & ".wav"
Object.Left = Object.Left + 1
If Object.Left > System.ScreenWidth Then Object.Left = System.VscreenLeft - Object.width * 2'- Object.Width
End Sub
Sub Object_OnTimer2
ChangeSound
End Sub
Sub Object_OnMouseEnter
ChangeSound
End Sub
Sub ChangeSound
Object.ToolTipText = "Playing marvin" & Object.PersistStorage("soundNUM") & ".wav"
Object.Sound = "marvin" & Object.PersistStorage("soundNUM") & ".wav"
Object.PersistStorage("soundNUM") = Object.PersistStorage("soundNUM") + 1
If Object.PersistStorage("soundNUM") > 16 Then Object.PersistStorage("soundNUM") = 1
End Sub
Now you may continue your experiments.
Best Regards.
Reply #3 Monday, March 5, 2007 3:59 PM
Vad_M,
I'll have to try this when I get home later. Thanks for taking the time to help a scripting newbie.
Reply #4 Tuesday, March 6, 2007 6:30 AM
And I'm always ready to help them.Reply #5 Thursday, March 8, 2007 5:04 PM
Reply #6 Thursday, March 8, 2007 7:59 PM

Finally, I inserted this piece of code to the script.
Sub object_onstatechange(state)
If state = "Show" Then
system.Volume = 85
ElseIf state = "Hide" Then
system.Volume = 0
End If
End Sub
So basically, the widget needs to have a "Show" state and a "Hide" state. (Both states should be assigned images). Then insert the script. I'm not sure what method you are using to hide and show Marvin and if this will work with that.
Reply #7 Friday, March 9, 2007 6:54 AM
You may use code that advises sVis. It will work nice.
The second way - you may use the "WMPlayer.OCX" ActiveX object to do this (use Google to find info about). You will not touch the system volume in the last case.
Best Regards.
Reply #8 Friday, March 9, 2007 8:15 AM
Is that possible?
Reply #9 Friday, March 9, 2007 8:19 PM
Zubaz- yes, this is probably possible through manipulating the Z-order, but hey, man, I'm just trying to figure out hide and show right now!
Please login to comment and/or vote for this skin.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
- Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!







Reply #1 Monday, March 5, 2007 6:12 AM