Jump to content
Search Community

unloading of swf dont unload its sounds

smeagol16 test
Moderator Tag

Recommended Posts

Hey every one!

I got one little problem.

 

im loading some swf that contains simple video player inside with play and pause btn by:

var oneSwf:SWFLoader = new SWFLoader("one.swf", {
								 alpha:0,
								 x:-350,
								 y:-240,
								 container:video_mc,
								 onComplete:completeHandler9});

function completeHandler9(event:LoaderEvent):void
{
	var loadedswf:ContentDisplay = event.target.content;
	TweenLite.to(loadedswf, 1, {delay:1, alpha:1} );
}

with oneSwf.load(); in CLICK function of some mc. I have another mc thats unloads that swf by:

TweenLite.delayedCall(0, oneSwf.unload);

When i test it via flash everything runs great, video is playing then stops while removing swf, and i can do it over and over.

 

Problems starts when i put that side on my server and want to try same thing.

When i load that swf first time i can play video and unload it without any problem, sounds of the movie unloads with swf.

But, when i load it again, hit play and want to unload it, the sounds of that movie are still playing...

They stops if I again load that swf and unload it.

 

here's the video swf code

var nc:NetConnection = new NetConnection();
nc.connect(null);

var ns:NetStream = new NetStream(nc);

var vid:Video = new Video(640, 360);
this.addChild(vid);

vid.attachNetStream(ns);

vid.y = 60;

ns.play("one.flv");
ns.pause();   
ns.addEventListener(NetStatusEvent.NET_STATUS, netstat);

function netstat(stats:NetStatusEvent)
{
   trace(stats.info.code);
}

var netClient:Object = new Object();
netClient.onMetaData = function(meta:Object)
{
   trace(meta.duration);
};

ns.client = netClient;

play_mc.buttonMode = true;
pause_mc.buttonMode = true;

play_mc.addEventListener(MouseEvent.CLICK, playClick);
pause_mc.addEventListener(MouseEvent.CLICK, pauseClick);

function playClick(e:MouseEvent):void
{
	ns.resume();
}

function pauseClick(e:MouseEvent):void
{
	ns.pause();
}

 

And here's the link when u can see my problem (section Video: ONE)

http://www.bonlao.com/annatokarska/

 

 

EDIT:

i saw that this problem is only when i use play/pause buttons. When i run same swf without buttons with autoplay and im closing it, the sounds stops every time when i unload that swf.

Link to comment
Share on other sites

Sounds like you're not cleaning up your stuff in your child swf for garbage collection. Here's an excerpt from the LoaderMax ASDocs (http://greensock.com/as/docs/tween/com/ ... oader.html):

 

A lot of effort has gone into making SWFLoader solve common garbage collection problems related to loading and unloading swfs, but since it is impossible for SWFLoader to know all the code that will run in the child swf, it cannot automatically remove event listeners, stop NetStreams, sounds, etc., all of which could interfere with garbage collection. Therefore it is considered a best practice to [whenever possible] build each subloaded swf so that it has some sort of dispose() method that runs cleanup code (removes event listeners, stops sounds, closes NetStreams, etc.). When the swf is loaded, you can recursively inspect the chain of parents and if a ContentDisplay object is found (it will have a "loader" property), you can add an "unload" event listener so that your dispose() method gets called accordingly. For example, in the child swf you could use code like this:

var curParent:DisplayObjectContainer = this.parent;
while (curParent) { 
   if (curParent.hasOwnProperty("loader") && curParent.hasOwnProperty("rawContent")) { //ContentDisplay objects have "loader" and "rawContent" properties. The "loader" points to the SWFLoader. Technically it would be cleaner to say if (curParent is ContentDisplay) but that would force ContentDisplay and some core LoaderMax classes to get compiled into the child swf unnecessarily, so doing it this way keeps file size down. 
       Object(curParent).loader.addEventListener("unload", dispose, false, 0, true); 
   }
   curParent = curParent.parent;
}

function dispose(event:Event):void { 
   //do cleanup stuff here like removing event listeners, stopping sounds, closing NetStreams, etc... 
}

 

You MUST close your NetStream properly before you unload the SWF or else risk things not getting GC'd properly (which could cause you to keep hearing the audio).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...