flash player crashes while looping over movies

1.3k views Asked by At

I'm trying to realize kind of a slideshow in flash, which loops over about 100 h.264 encoded movies. I'm using the NetConnection and NetStream classes for connecting to the files locally on my harddisk (see code below).

private function playMovie():void
{           
        var currentMovie:String = movies[index];
        index = (index + 1) % movies.length;

        netConnection = new NetConnection();
        netConnection.connect(null);

        if(netStream != null)
        {
            netStream.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);         
            netStream = null;
        }

        netStream = new NetStream(netConnection);
        netStream.client = this;
        netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

        stageVideo.attachNetStream(null);
        stageVideo.attachNetStream(netStream);

        netStream.play(currentMovie);
}

private function netStatusHandler(evt:NetStatusEvent):void
{
        if(evt.info.code == "NetStream.Play.Stop")
        {
            playMovie();
        }
}

public function onMetaData(e:Object):void 
{
        netStream.seek(int(e["duration"]));
}       
public function onXMPData (e:Object):void {}

the problem is that the memory usage of the flashplayer increases with every movie and when reaching about 1.3gb it just ends itself without any errormessage.

my question obviously: how can i fix that?

1

There are 1 answers

16
weltraumpirat On BEST ANSWER

You must call NetConnection.close() to free the resources, otherwise your memory usage will increase as you see it. It is better practice, though, to keep the same NetConnection and NetStream objects, once created, to play different videos:

private function playMovie():void
{           
    var currentMovie:String = movies[index];
    index = (index + 1) % movies.length;

    if ( netConnection == null ) 
    {
        netConnection = new NetConnection();
        netConnection.connect(null);
    }

    if ( netStream == null )
    {
        netStream = new NetStream(netConnection);
        netStream.client = this;
        netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        stageVideo.attachNetStream(netStream);
    }

    netStream.play(currentMovie);
}