Hi everyone!
I’m experiencing a few memory leaks each time my swf gets reloaded. I have closed the netstream, removed the listeners and the container, tried UnloadAndStop(); but in the end I’m still missing someting as some Mb leak anyways…
Can someone point what am I doing wrong?
Thanks!!
Here goes my child swf source code:
////////// UrbanRevolution :MoD
////////// Built on "Video player a la Hulu" by Chris Brimelow http://chrisbrimelow.com
////////// FS function by noponies http://www.noponies.com/dev/as3_fsresize/
////////// XML Adobe VIDEO JukeBox AC3 Lessons
package {
//import flash.media.SoundTransform;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.utils.Timer;
import caurina.transitions.*;
import flash.events.*;
import flash.display.*;
import noponies.display.NpFSObjectResize;
public class VideoJukebox extends MovieClip {
/**
* The amount of time between calls to update the playhead timer, in
* milliseconds.
*/
const PLAYHEAD_UPDATE_INTERVAL_MS:uint = 10;
/**
* The path to the XML file containing the video playlist.
*/
const PLAYLIST_XML_URL:String = "playlist.xml";
/**
* The client object to use for the NetStream object.
*/
var client:Object;
/**
* The index of the currently playing video.
*/
var idx:uint = 0;
//var meta:Object;
var nc:NetConnection;
var ns:NetStream;
var playlist:XML;
var t:Timer;
var uldr:URLLoader;
var vid:Video;
var videosXML:XMLList;
/**
* Constructor
*/
public function VideoJukebox() {
// Initialize the uldr variable which will be used to load the external
// playlist XML file.
uldr = new URLLoader();
uldr.addEventListener(Event.COMPLETE, xmlCompleteHandler,false, 0, true);
uldr.load(new URLRequest(PLAYLIST_XML_URL));
}
/**
* Once the XML file has loaded, parse the file contents into an XML object,
* and create an XMList for the video nodes in the XML.
*/
function xmlCompleteHandler(event:Event):void {
playlist = XML(event.target.data);
videosXML = playlist.video;
main();
}
/**
* The main application.
*/
function main():void {
// Create the client object for the NetStream, and set up a callback
// handler for the onMetaData event.
client = new Object();
client.onMetaData = metadataHandler;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler,false, 0, true);
ns.client = client;
// Initialize the Video object, attach the NetStram, and add the Video
// object to the display list.
vid = new Video();
vid.attachNetStream(ns);
//vid.x = 0;
//vid.y = 0;
vid.width = 1360;
vid.height = 768;
vid.smoothing = true;
vid_mc.addChild(vid);
// Begin playback of the first video.
playVideo();
// Initialize the Timer object and set the delay to
// PLAYHEAD_UPDATE_INTERVAL_MS milliseconds.
t = new Timer(PLAYHEAD_UPDATE_INTERVAL_MS);
// Configure the various Button instances. Each Button instance uses
// the same click handler.
}
/**
* Event listener for the ns object. Called when the net stream's status
* changes.
*/
function netStatusHandler(event:NetStatusEvent):void {
try {
switch (event.info.code) {
case "NetStream.Play.Start" :
// If the current code is Start, start the timer object.
t.start();
break;
case "NetStream.Play.StreamNotFound" :
case "NetStream.Play.Stop" :
// If the current code is Stop or StreamNotFound, stop
// the timer object and play the next video in the playlist.
t.stop();
playNextVideo();
break;
}
} catch (error:TypeError) {
// Ignore any errors.
}
}
function metadataHandler(metadataObj:Object):void {
}
/**
* Retrieve the current video from the playlist XML object.
*/
function getVideo():String {
return videosXML[idx].@url;
}
/**
* Play the currently selected video.
*/
function playVideo():void {
var url:String = getVideo();
ns.play(url);
}
function playNextVideo():void {
if (idx < (videosXML.length() - 1)) {
idx++;
playVideo();
} else {
idx++;
nc.close();
ns.close();
vid.attachNetStream(null);
removeChild(vid_mc);
vid.clear();
MovieClip(parent.parent).ParentFunction(); // remete para a função ParentFunction na timeline prinicpal
vid_mc.unloadAndStop();
}
}
}
}