2012-05-17 64 views
1

我只是想開始我的網絡攝像頭來顯示視頻,爲此我編寫了這段代碼,但它不工作。任何想法爲什麼它不能工作?我可能會犯什麼錯誤?將相機與Flash Builder 4.6相連

請這裏是代碼,

<?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> 

相反,我看到彈出一個錯誤:

類型錯誤:錯誤#1009:無法訪問空對象引用的屬性或方法。 (C:\ Users \ Malik \ Adob​​e Flash Builder 4.6 \)下的 在vv/video_d_creationCompleteHandler()[C:\ Users \ Malik \ Adob​​e Flash Builder 4.6 \ vv \ src \ vv.mxml:15] 在flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core :: UIComponent/dispatchEvent()[E:\ vm \ src \ vv.mxml:26] at flash.events::EventDispatcher/dispatchEventFunction 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 \ fr ameworks \ projects \ framework \ src \ mx \ managers \ LayoutManager.as:1180]

等待您的答案,非常感謝。 謝謝 Bilal艾哈邁德

回答

2

您的VideoDisplay.videoObjectnull。 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

+0

謝謝!我沒有嘗試過你的代碼,但鏈接是有幫助的。 –

+0

較短的解決方案:http://stackoverflow.com/a/37363951/900408 – davee44