2

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?

Hunternif
  • 2,370
  • 2
  • 17
  • 14
  • Why you cant listen for net stream status event and when it is closed, then stop your code from updating the speed of download. – Triode Mar 20 '12 at 12:58

1 Answers1

2

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.

James Tomasino
  • 3,520
  • 1
  • 20
  • 38
  • Thank you, James! The try..catch was what I needed (I've completely forgotten about it). – Hunternif Mar 20 '12 at 18:30
  • 1
    Actually, your code would still cause the error to be thrown, because when a NetConnection closes, the NetStream associated with it still exists, and it's the getter for info that throws the error. Which is pretty strange to me, it would do much better to simply return null. – Hunternif Mar 20 '12 at 18:32