我只是想开始我的网络摄像头来显示视频,为此我编写了这段代码,但它无法正常工作。知道为什么一定不能工作吗?我可能犯了什么错误?
请在这里输入代码,
<?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>
相反,我看到弹出窗口出现错误:
TypeError:错误#1009:无法访问空对象引用的属性或方法。 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] 在flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() 在mx.core :: UIComponent / dispatchEvent()[E:\ dev \ 4.y \ frameworks \ projects \ framework \ src \ mx \ core \ UIComponent.as:13152] 在mx.core :: UIComponent / set initialized()[E:\ dev \ 4.y \ frameworks \ projects \ framework \ src \ mx \ core \ UIComponent.as:1818] 在mx.managers :: LayoutManager / doPhasedInstantiation()[E:\ dev \ 4.y \ frameworks \ projects \ framework \ src \ mx \ managers \ LayoutManager.as:842] 在mx.managers :: LayoutManager / doPhasedInstantiationCallback()[E:\ dev \ 4.y \ frameworks \ projects \ framework \ src \ mx \ managers \ LayoutManager.as:1180]
非常感谢等待你的回答。 谢谢 比拉尔艾哈迈德
答案 0 :(得分:2)
您的VideoDisplay.videoObject
是null
。 AFAIK可以像here一样修复。如果您不喜欢这种方法,可以这样做:
<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>
或者使用好的旧mx:VideoDisplay
。