robertmacedonia 0 Junior Poster in Training

Hello to all,

I am building an application in AS3 that loads swf files using UILoader. Each swf file has its own sounds included and the problem is that when I load the files - I load them all at once, and I need to show one at a time, then one would navigate to the following swf using a Next button etc..

Now, as I said - since each file has its own sounds, when I show the first swf to the user, all of the swf's sounds are loaded and the user gets a complete mess of sounds, all of them mixed up.

So now I've been told that I should store all of the swfs in an array, converted to MovieClips so that I would be able to use its "soundTransform" property to set the volume to 0 etc...

Now, my question is - how do I possibly store the swfs in an array as MovieClips...

Something like - "swf_array[0] = MovieClip(loader.content);", but I haven't got a clue about looping through the loader to store each external file in its own element of the array. I have got this code for loading only, it works fine, so can someone help me a little about getting each of the files and storing them in an array?

this.zadaca = new ContainerZadaca();
				this.zadaca.name = "zad_" + zadaci_array[j];
				this.zadaca.x = 22;
				this.zadaca.y = 113;
				//this.zadaca.zadaca_loader.scaleX = 0.8;
				//this.zadaca.zadaca_loader.scaleY = 0.8;
				
				this.zadaca.zadaca_loader.addEventListener( Event.COMPLETE, onCompleteLoadZadacaTest );
				
				this.url_request_zadaca = new URLRequest("../../db/zadaci/" + zadaci_array[j] + ".swf");
				
				this.zadaca.zadaca_loader.load(this.url_request_zadaca);

Now how to include something like this:

this.niza_swf[j] = MovieClip(this.zadaca.zadaca_loader.content[j]);

Dani AI

Generated

's idea to cast each loaded SWF to a MovieClip and keep them in an array is valid for controlling timeline playback, but the most reliable way to prevent all SWF sounds from mixing is to mute each loader as soon as the file finishes loading and then unmute only the SWF that is shown. Storing the Loader instances (or their content objects) in an array gives per-SWF control: stop the timeline on the MovieClip, and control volume via the LoaderInfo.soundTransform.

A practical flow:

  • Queue SWFs into Loader objects and keep those Loaders in an array.
  • In the COMPLETE handler set the loader's soundTransform to zero and cast content to MovieClip and call stop() to halt timeline/stream audio.
  • When presenting a SWF, restore its LoaderInfo.soundTransform to the desired volume, add its content to the display list, and call play() on the MovieClip if needed.

Example (minimal) pattern:

var loaders:Array = [];
var pages:Array = [];

function queueLoad(url:String):void {
  var L:Loader = new Loader();
  L.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
  L.load(new URLRequest(url));
  loaders.push(L);
}

function onLoaded(e:Event):void {
  var info:LoaderInfo = LoaderInfo(e.target);
  info.soundTransform = new SoundTransform(0); // mute until shown
  var mc:MovieClip = info.content as MovieClip;
  if (mc) mc.stop();
  pages.push(info.content);
}

Caveats: timeline "Stream" sounds stop when the timeline is stopped; "Event" sounds are played via SoundChannel and can continue unless muted or explicitly stopped inside the child SWF. If Event sounds persist, either expose an API in the child SWF to stop them or rely on LoaderInfo.soundTransform to silence that loader. For reference see LoaderInfo.soundTransform and SoundTransform in the ActionScript 3 docs: LoaderInfo.soundTransform and SoundTransform.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.