Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.
secretrobotron edited this page Jul 15, 2011 · 9 revisions

Butter API (v0.1)

Core Module

Butter

trigger( name, options )

Triggers an event with type name. The event will be sent to each listener waiting for events of type name, with options as the only parameter.

listen( name, handler )

Listen for an event with type name. When an event occurs with type name, handler will be called. To receive data from the event, handler should take one parameter in its signature.

unlisten( name, handler )

Stop listening for events with type name. If handler is specified, all listeners for type name will be forgotten. Otherwise, only the listener matching handler will be effected.

addTrackEvent( track, trackEvent )

Add TrackEvent trackEvent to Track track. track may be a Track object (see below), or a string, representing the name of a stored Track. trackEvent may be a TrackEvent or an object representing the parameters to create a TrackEvent (object parameters are passed directly to the TrackEvent constructor). Returns a TrackEvent if successful, and dispatches a trackeventadded event. Throws an error if track is invalid, or no Media is defined.

getTrackEvents()

Returns an object whose properties are the names of stored Tracks. Each property references an array of TrackEvents belonging to the corresponding Track.

getTrackEvent( track, name )

Searches through Track track for a TrackEvent named name, and returns it if successful.

removeTrackEvent( track, trackEvent )

Searches through Track track for TrackEvent trackEvent, or one named trackEvent, and forgets it if successful. Upon removal, the corresponding TrackEvent is returned, and a trackeventremoved event is dispatched.

addTrack( track )

Stores Track track in the current Media. If track is and object with properties to create a Track, it will be passed directly to the Track constructor first, and the consequent Track will be stored. The Track object will be returned, and a trackadded event will be dispatched. Throws an error if no Media is defined.

getTracks()

Returns an array of Tracks from the current Media. Throws an error if no Media is defined.

getTrack( name )

Searches for a Track named name and returns it if successful. Throws an error if no Media is defined.

removeTrack( track )

Searches for Track track and removes it if successful. track may be a string representing a named Track, or the Track object to be removed itself. Upon removal, the corresponding Track is returned, and a trackremoved event is dispatched. Throws an error if no Media is defined.

addTarget( target )

Stores Target target. If target is an object with properties to create a Target, the object will be passed directly to the Target constructor first, to create a Target object to be stored instead. The Target object is returned, and a targetadded event is dispatched.

removeTarget( target )

Searches for Target target, and removes it if successful. target may be a Target object, or a string representing the name of one. Upon removal, the corresponding Target object is returned, and a targetremoved event is dispatched.

getTargets()

Returns an array of the currently stored Target objects.

getTarget( name )

Searches for a Target named name and returns it if successful.

importProject( projectData )

exportProject()

setProjectDetails()

getProjectDetails()

play()

Plays the current Media object.

pause()

Pauses the current Media object.

currentTime()

Gets the current time of the current Media object.

getAllMedia()

Returns an array containing all stored Media objects.

getCurrentMedia()

Returns the currently selected Media object.

getMedia( name )

Searches for a stored Media object named name, and returns it if successful.

setMedia( media )

Sets the current Media to media, which may be a Media object, or a string representing the name of one. The referenced Media object must be added first (see addMedia below). Dispatches a mediachanged event if successful.

addMedia( media )

Stores Media media, returns it, and dispatches a mediaadded event.

removeMedia( media )

Searches for the stored Media object media, and removes it if successful. media may be a Media object, or a string representing the name of one. Upon removal, the Media object is returned, and a mediaremoved event is dispatched.

getScriptLocation()

Class Method Attempts to return the location of the current butter.js script.

registerModule( name, module )

Class Method and Instance Method Registers a Butter module, and extends the API to include methods from the module.

extendAPI( properties )

Class Method Extends the API. The Butter class and new instances of Butter objects will receive API additions.

Track

getName()

getId()

getTrackEvent( trackId )

getTrackEvents()

removeTrackEvent( trackEvent )

addTrackEvent( trackEvent )

TrackEvent

start

end

type

popcornOptions

popcornEvent

track

getName()

getId()

Target

object

getName()

getId()

Media

setMedia( mediaElement )

getMedia()

getName()

getTracks()

addTrack( track )

getTrack( name )

removeTrack( track )

Comm Module

CommClient

listen( type, callback )

forget( type, callback )

send( message, type )

CommServer

bindFrame( name, frame, readyCallback, messageCallback )

bindClientWindow( name, client, callback )

listen( name, type, callback )

forget( name, type, callback )

send( name, message, type )