

/*
 Plays a sound when you click the object.
 
 This works good for menus, in combination with for example the genericButton behavior.
 
 Note:
 The menuID related lines I use in my project, 
 to allow only one menu to have "focus".
 
 The $currentMenu global variable would be set to different values as you show different menus.
  
*/ 
 


if (!isObject(MouseClickSoundBehavior))
{
   %template = new BehaviorTemplate(MouseClickSoundBehavior);
   
   %template.friendlyName = "Mouse Click Sound";
   %template.behaviorType = "Audio";
   %template.description  = "Play a sound when the user clicks this object. ";


  // %template.addBehaviorField(menuID,     "The menu this belongs to", int,  0 ); 
   %template.addBehaviorField(sound, "The sounds audio profile.", string ,"test"   );
   
} 
 

function MouseClickSoundBehavior::onBehaviorAdd(%this)
{ 
    %this.owner.setUseMouseEvents(true);  
}

function MouseClickSoundBehavior::onMouseUp(%this, %modifier, %worldPos)
{ //if ($currentMenu != %this.menuID) return;
  if ( isobject(%this.sound) )       
   alxPlay(   %this.sound );
  else echo( "MouseOverSoundBehavior: Invalid Audio Profile! " @  %this.sound );        
}
