Reputation: 301
I just want to start my webcam to display video, for this I wrote this code but it is not working. Any idea why It must not be working ? What possibly I might be making mistake ?
Please here is the code,
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.controls.Alert;
protected function video_d_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
var camera:Camera = Camera.getCamera();
if (camera) {
video_d.videoObject.attachCamera(camera);
} else {
Alert.show("You don't seem to have a camera.");
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:VideoDisplay x="15" y="23" id="video_d" creationComplete="video_d_creationCompleteHandler(event)" />
</s:Application>
Instead I see the popup with an error:
TypeError: Error #1009: Cannot access a property or method of a null object reference. at vv/video_d_creationCompleteHandler()[C:\Users\Malik\Adobe Flash Builder 4.6\vv\src\vv.mxml:15] at vv/__video_d_creationComplete()[C:\Users\Malik\Adobe Flash Builder 4.6\vv\src\vv.mxml:26] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:13152] at mx.core::UIComponent/set initialized()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:1818] at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:842] at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]
Awaiting your answers with many thanks. Thanks Bilal Ahmad
Upvotes: 1
Views: 3384
Reputation: 831
Your VideoDisplay.videoObject
is null
. AFAIK it can be fixed like here. If you don't like this approach it's possible to do something like this:
<s:VideoDisplay x="15" y="23" id="video_d" creationComplete="video_d_creationCompleteHandler(event)">
<s:source>
<s:DynamicStreamingVideoSource host="" streamType="{StreamType.LIVE}">
<s:DynamicStreamingVideoItem />
</s:DynamicStreamingVideoSource>
</s:source>
</s:VideoDisplay>
Or use good old mx:VideoDisplay
.
Upvotes: 2