Class SoundManager2::SoundManager
In: lib/sound_manager2.rb
Parent: Object

Represents the Javascript SoundManager2 API. We use this class to generate Javascript for an HTML ERB template that will then actually invoke the SoundManager2 API at runtime in the user‘s browser.

Methods

Public Class methods

Creates an empty SoundManager instance.

[Source]

    # File lib/sound_manager2.rb, line 72
72:     def initialize
73:       @sounds = []
74:     end

Public Instance methods

Create a Sound object and to the list that will generate Javascript later in the onload_function.

[Source]

    # File lib/sound_manager2.rb, line 77
77:     def create_sound(sound_id, url)
78:       @sounds << Sound.new(sound_id, url)
79:     end

Returns the Javascript code to initialize the SoundManager2 API via it‘s "soundManager.onload" function. Basically, this method is called by the initialize helper methods when creating a list of sounds to play later.

[Source]

    # File lib/sound_manager2.rb, line 89
89:     def onload_function
90:       output = "soundManager.onload = function() {\n"
91:       
92:       @sounds.each do |sound|
93:         output += %Q{\tsoundManager.createSound("#{sound.id}", "#{sound.url}");\n}
94:       end
95:       
96:       output += "}"
97:     end

Is there a need to create an onload_function Javascript definition?

[Source]

    # File lib/sound_manager2.rb, line 82
82:     def onload_function?
83:       !@sounds.empty?
84:     end

[Validate]