2015-10-21 64 views
9

我正在使用ScanHardware函數來獲取更新的相機列表。如果將相機插入我的Mac mini,相機長度正在更新。如果我插入了相機,我的應用程序突然關閉。as3 scanHardware()函數使我的應用程序崩潰

<?xml version="1.0" encoding="utf-8"?> 
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" 
         height="280" 
         width="280" 
         creationComplete="test1()"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <fx:Script> 
     <![CDATA[ 

      import mx.controls.Alert; 
      public var hardwareTimer:Timer; 
      public function test1():void{ 
       hardwareTimer = new Timer(5000); 
       hardwareTimer.addEventListener(TimerEvent.TIMER,refreshHardware); 
       hardwareTimer.start(); 
      } 
      public function refreshHardware(ev:TimerEvent):void{ 

       flash.media.scanHardware(); 
       Alert.show(Camera.names.length.toString()); 
      } 
     ]]> 
    </fx:Script> 
</s:WindowedApplication> 

如果我使用Camera.names我拔掉任何Camera後,我的應用程序崩潰。

如何解決這個問題?

+1

您的代碼在Windows 10中正常工作。在其他機器上試用它,如果它工作正常,那麼您的機器中可能存在一些問題(AIR版本,凸輪驅動程序,...)... – akmozo

+0

它工作正常在Windows上,我試過了。但它不適用於Mac。 – Vishnu

回答

2

Actionscript錯誤不應導致應用程序崩潰。當應用程序崩潰時,通常是因爲它試圖在本機級別進行非法操作,如寫入保留/無效內存。 我會從相機或USB尋找問題開始。如果您可以使用不同品牌的網絡攝像頭重現問題,則可以排除相機硬件&驅動程序。如果您可以在另一臺Mac上重現問題,那麼它可能不是USB。