Skip to main content
Participant
December 1, 2009
Question

How do I write a halt script vs an onComplete script?

  • December 1, 2009
  • 1 reply
  • 499 views

I am having an issue with a swf playing over another swf.  The stop audio portion of my ActionScript is occurring onComplete rather then a halt script action.  This was not a problen when I tested locally since the files would download in 1 or 2 seconds instead of 8 to 12 seconds.   Can someone tell me how to change the onComplete to a halt action?  My script is below.


//run at once

var sRequest:URLRequest = new URLRequest("track01.swf");
var externalMovie:MovieClip;


var swfLoader:Loader = new Loader();
swfLoader.load(sRequest);
this.addChild(swfLoader);

swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

function onComplete(evtObj:Event):void{

  externalMovie = MovieClip(swfLoader.content)
 
}

//------------------button code

this.addEventListener(MouseEvent.CLICK, onClick);

function onClick(evtObj:MouseEvent):void{

externalMovie.stop();

//this.removeChild(swfLoader);
//trace(evtObj.target.name)

var buttonClicked:String = evtObj.target.name;

swfLoader.load(new URLRequest(buttonClicked + ".swf"));

}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
December 1, 2009

is there sound in track01.swf that you're trying to stop?  if so, you can use unloadAndStop() if you're publishing for fp 10.  or you can use SoundMixer.stopAll() to stop all sounds everywhere.  or, you can explicitly stop the sound in the loaded swf.

applying stop() to the loaded swf's main timeline won't help unless you're streaming your sound in the loaded swf and the sound is attached to the loaded swf's main timeline.

ChjavaAuthor
Participant
December 1, 2009

Hello - Thank you for responding. I am very new to AS3 and I am not certain how I make the unloadAndStop() work in the code I have. There is sound in each of the 19 loaded swf. I am publishing for 10. I think the stop(); you are referring to is for my website link.

The issue is in this portion of the code. I tried changing the code to externalMovie.unloadAndstop(); and it didn't help. Is this a function that replaces swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete); ?

This is the link to the page, if it would help to see what going wrong.

http://www.firstcommusic.net/amped/nov-dec/in_theQ.html

///////////////////////////////////////////////////

//run at once

var sRequest:URLRequest = new URLRequest("TV_track01.swf");

var externalMovie:MovieClip;

var swfLoader:Loader = new Loader();

swfLoader.load(sRequest);

this.addChild(swfLoader);

swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

function onComplete(evtObj:Event):void{

externalMovie = MovieClip(swfLoader.content)

}

//

kglad
Community Expert
Community Expert
December 1, 2009

unloadAndStop() is applied to the loader of a swf that you want to unload and stop all the swf's streams (including sounds):

function unloadAndStopF(e:MouseEvent){

swfLoader.unloadAndStop();

}