Macromedia dreamweaver 8-extending dreamweaver User Manual

Page of 504
The Behaviors API
315
canAcceptBehavior()
Description
This function determines whether the action is allowed for the selected HTML element and 
specifies the default event that should trigger the action. Can also check for the existence of 
certain objects (such as SWF files) in the user’s document and not allow the action if these 
objects do not appear.
Arguments
HTMLElement
The argument is the selected HTML element.
Returns
Dreamweaver expects one of the following values:
true
 value if the action is allowed but has no preferred events.
A list of preferred events (in descending order of preference) for this action. Specifying 
preferred events overrides the default event (as denoted with an asterisk [*] in the Event 
file) for the selected object. See step 1 in 
false
 value if the action is not allowed. 
If the 
canAcceptBehavior()
 function returns a 
false
 value, the action is dimmed in the 
Actions pop-up menu on the Behaviors panel.
Example
The following instance of the 
canAcceptBehavior()
 function returns a list of preferred 
events for the behavior if the document has any named images:
function canAcceptBehavior(){ 
var theDOM = dreamweaver.getDocumentDOM();
// Get an array of all images in the document
var allImages = theDOM.getElementsByTagName('IMG'); 
if (allImages.length > 0){
return "onMouseOver, onClick, onMouseDown";
}else{
return false;
}
}