Skip to main content
December 13, 2009
Question

loading a sound twice causes error

  • December 13, 2009
  • 2 replies
  • 631 views

I am trying to load a sound in an mp3 player based on the selection of a user who

has the .swf embedded in a web page. The first time the user makes a selection

the selection loads with no problem. But if the user stops the sound or lets it play

to the end and starts it again, I have to be careful not to call sound.load(URLRequest)

again.

If the user has chosen another selection to listen to, then load() has to be called again.

The question is:

how do I unload the sound Obj so another mp3 file can be loaded into it and played?

I would think that load(another URLRequest) would overwrite the first and not complain.

( a deeper question is where is the sound file stored, by the browser -- in the case of

html embed-- or does the Flash plugin maintain its own cache?)

Thank you for time, attention, and advice, info, etc.

JK

PS: I realize that load() has more use than for sound objects

This topic has been closed for replies.

2 replies

December 15, 2009

Thanks to those who responded.

I have it working past this problem. Now I can load on track via html/javascript

play it, stop the playback, load another selection and play it with out problems

so far.

Only one phantom problem with graphic element positioning when the pause

button is used and the play button is used to restart the play back. I will figure

this out.

Some features I have planned: set marker that can be started from, played to

of played between. When there is a marker, the user can define a segment.

once a segment has been defined for a track, the user can play and replay the

segment without having to define it every time.

Additionally, I will investigate and code for offering the user the opportunity

to save marker and segment information for a track as a shared object or

to save as file on the server(for users registered with the site).

JK

kglad
Community Expert
Community Expert
December 13, 2009

can only use the load method once, per sound instance.

to load a 2nd sound, create a 2nd sound instance.

December 13, 2009

Thank you for the reply.

So, if there is a changeable play list length, I need to create new

objects for each

list item dynamically? And all the necessary objects cannot be hard

coded. The

name for each object has to be generated programmatically.

As it is programmed, my app has server code that opens and reads a play

list

directory and creates an html list of the contents. So managing the

content is

just a matter of adding or removing files from the play list directory.

This would mean that for every selection the user loads and plays, an

object will

persist. It would be nice to be able to unload selections to reduce the

memory

use. Or limit the size of each mp3 file, as well as the list length.

As it is the only way to load a new selection is to reload the browser

window.

That suggests that the browser cache holds the content of the object,

perhaps

as a parent of the Flash plugin or activeX control(?).

I am sorry this is long winded, but these nuances are obscure in

manuals and

texts.

JK

kglad
Community Expert
Community Expert
December 13, 2009

yes, you'll create a new sound instance for each sound file that needs to be loaded.

objects or, in this situation, sound instances will persist and occupy memory just like everything else in as3, unless you explicitly ready the instance for gc.

reloading your swf is not necessary if you create a new sound instance for each sound file that needs to be loaded.