Flash AS3 FLVPlayback Component Bug?
- November 21st, 2008
- Posted in Flash
- Write comment
Seems that if the FLVPlayback component in Flash CS3 (AS3)Â is currently playing a FLV and the timeline changes to a frame without a FLV component, without stopping the movie first, that the stream continues.
To reproduce: Set up a Flash CS3/AS3 file. Create a FLVPlayback component on one frame (only one frame), set up a source (via AS3 or via component parameters) and create a few blank frames. Add navigation buttons that exist on all frames and add event listeners for the buttons so you can jump between the frames. Run the movie and navigate to the frame with the FLVPlayback on it, and then navigate away. The audio continues but the component instance is gone.
What I found very interesting is that I could trace the instane name of the removed component afterwards, but if I tried to gain a reference to it via getChildByName, it came back null.   I also found that after adding stop (within a try catch), that it would work when going backwards on the timeline, but not forwards. And then if I jumped ahead and came back, that I could create overlapping audio. Very very weird.
Download Sample file. Run the sample file and navigate around — you’ll see some very odd behavior.
Now, the easy answer is “just don’t build it that way” or numerous other workarounds & fixes, but reality is that a number of beginning users are used to using frames/frame labels and it is would make sense to only have the component on the frame you needed it. My question is –> Whats really going on behind the scenes? (I have a few ideas).
Kudos to my Flash Level 2 students. They are great at finding bugs in documentation and components.
That’s not a bug in the component, that’s a failure of design. What you’ve done is remove the component from the display list, but the references to the Netstream object is still present, so the sound is never garbage-collected. If you want the audio to be GC’ed without actually stopping the video, your only option is to use FP10′s unloadAndStop() method, and maybe the GC will kick in, eventually. The surest bet is to actually call flvpb.pause() or stop() before you navigate away to another frame. Even better, pause the video and make the component alpha equal to zero, or move it off-stage. Re-instantiation of the component is expensive memory-wise, so you’d do best to not delete the component if want to hide it. I’d even suggest creating a custom function that calls flvpb.pause/stop() and moves the instance off-stage if you want the component to disappear, rather than deleting it and having to deal with garbage-collection issues.
Joeflash –
I actually had given my students the work-around of leaving the video offstage at all times. But having many of them come from Flash CS3/AS2 background or Flash level 1 (drawing and animating only), this is something that always worked for them in the past, and “breaks” now. Its easy to get into discussions about GC with developers, but new students have a rough time starting out with discussions on it. Particularly when they are just learning ActionScript.
I’d still classify this as a bug with the component (even though it may not be technically) and not a design flaw, because Adobe shouldn’t expect new students to understand and implement garbage collection for a simple video player and when using frame labels.