Flex VideoDisplay Bug and The Component Life Cycle


We ran into this strange problem at work this week, we were dealing with a Component class that uses the VideoDisplay component in Flex in order to play video. The class was unfortunately not consistent with the Flex Component life cycle guidelines. Working with the class, I wanted to be able to use the CuePointManager so I had to first set the property VideoDisplay.cuePointManagerClass. The problem was that even though I set this member, when examining the VideoDisplay instance in the debugger I got cuePointManagerClass=null. When I examined the VideoDispaly class I found the problem, the VideoDisplay code constructs the CuePointManager in a method that is called from CreateChildren the name of that method is createVideoPlayer.

<pre style="border: 1px dashed rgb(204, 204, 204); padding: 0px; background: rgb(240, 240, 240) url(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif) repeat scroll 0% 0%; overflow: auto; font-family: arial; font-size: 12px; width: 99%; height: auto; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: rgb(0, 0, 0); text-align: left; line-height: 20px;">1: private function createVideoPlayer():void
2: {
3: .
4: if (cuePointManagerClass)
5: {
6: _cuePointManager = new cuePointManagerClass(videoPlayer);
7: _cuePointManager.videoDisplay = this;
8: }
9: .
10: }
</pre>
The setter cuePointManagerClass simply states:

<pre style="border: 1px dashed rgb(204, 204, 204); padding: 0px; background: rgb(240, 240, 240) url(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif) repeat scroll 0% 0%; overflow: auto; font-family: arial; font-size: 12px; width: 99%; height: auto; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: rgb(0, 0, 0); text-align: left; line-height: 20px;">1: public function set cuePointManagerClass(value:Class):void
2: {
3: _cuePointManagerClass = value;
4: }
</pre>
In our scenario the above setter was called after the VideoDisplay class was added to the parent component, therefore, the class createChildren method followed by createVideoPlayer were already called, the setter did not invoke any invalidation method that could invoke createVideoPlayer and would make sure the cuePointManager is instantiated. Although this is a bug, we can avoid running into it if we stick to the Adobe’s Component codding conventions. The component life cycle docs and code samples hints that you should first instantiate and set all members of a new child and then add it using addChild

What are the lessons to be learned here?

<ol><li>Like any other engineering product, Flex SDK has bugs.</li><li>Following Adobe’s codding conventions will help you avoid running into troubles.</li></ol>

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com