Search code examples
actionscript-3flashapache-flexnetstream

NetStream.info, getting Error #2154


In my application I have a video playing from a NetStream. Every second on timer I update a text label with statistics like stream.info.currentBytesPerSecond. The problem occurs when the NetConnection associated with this NetStream closes: the getter for stream.info throws

Error: Error #2154:The NetStream Object is invalid.

The only solution for this seems to be to listen to NetStatus event and stop the timer when "NetConnection.Connect.Closed" gets caught.
Isn't there a better way to do this?


Solution

  • You could wrap your test for stream.info in a try..catch, I suppose. Or you could test to see if the object exists first:

    if (stream && stream.info) stream.info ...
    

    Really, though, the cleanest way would be to remove the applicable listener and perform cleanup when your connection closes.