处理 Flex 上的错误情况

发布于 2024-10-08 18:18:25 字数 820 浏览 5 评论 0原文

我有以下 AS 代码。我注意到,如果应用程序正在使用网络摄像头,则除非主应用程序关闭,否则任何辅助应用程序都无法使用它。

我的问题是,从下面的代码1.我们可以捕获该条件 2.如果没有检测到摄像头,如何发出警报,因为它是 AS 代码

编辑: 文件名是 cldAS.as 现在如何从任何.mxml 文件调用 cldAS() 。一些示例将不胜感激

 package org.com
 {
import flash.display.Sprite;
import flash.media.*;
import flash.net.*;


public class cldAS extends Sprite
{
    public function cldAS()
    {
        var cam:Camera =  Camera.getCamera();
        if(cam != null)
        {   

            cam.setMode(640, 480, 30);
            var video:Video = new Video(300, 450);
            video.attachCamera(cam);

            addChild(video);
        }
        else
        {
            trace("No Camera Detected");
                              //How to give an alert here 

        }
    }                   

}
  }

I have the following AS code.I have noticed that if an Application i s using the webcamera then it cannot be used by any secondary applications until unless the primary application is closed.

My question is that from the following code 1.can we capture that condition
2.If no camera is detected how to give the alert since it is an AS code

EDIT:
Filename is cldAS.as
Now how to call cldAS() from any.mxml file .Some example would be appreciated

 package org.com
 {
import flash.display.Sprite;
import flash.media.*;
import flash.net.*;


public class cldAS extends Sprite
{
    public function cldAS()
    {
        var cam:Camera =  Camera.getCamera();
        if(cam != null)
        {   

            cam.setMode(640, 480, 30);
            var video:Video = new Video(300, 450);
            video.attachCamera(cam);

            addChild(video);
        }
        else
        {
            trace("No Camera Detected");
                              //How to give an alert here 

        }
    }                   

}
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲娇萝莉攻 2024-10-15 18:18:25

Alert.show("您似乎没有网络摄像头。");
而不是
痕迹(...) ?

Alert.show("You don't seem to have a webcam.");
instead of
trace(...) ?

笑叹一世浮沉 2024-10-15 18:18:25

Alert仅在Flex中可用,在AS3中你应该真正实现自己的解决方案,另一方面,由于Alert是一个Javascript函数,你也可以使用ExternalInterface来调用它。

就实现您自己的解决方案而言,至少需要一个 TextField 来显示您的消息,您可以通过发送带有仅接受 String 的消息属性的 CustomEvent 来提供该文本。创建您自己的 Alert 类不需要太多工作。它将位于您的 App 之上,您可以在接收 CustomEvent 时切换可见性,并有一个关闭按钮来隐藏它。


您应该能够在 script 标签内调用您的 AS3 类,除此之外,我将向 Flex 专家留下更详细的答案。我不确定是否可以将 Sprite 直接添加到 Flex 中,因为我记得 Flex 中的对象必须继承自 UIComponent 才能添加到舞台,但请与这里的其他人确认,我没有在相当一段时间...

<mx:Script>
   import org.com.cldAS;

   public cld:cldAS = new cldAS();
</mx:Script>

Alert is available in Flex only , in AS3 you should really implement your own solution, on the other hand , since Alert is a Javascript function , you could also use ExternalInterface to call it.

As far as implementing your own solution is concerned, at the minimum you need a TextField to display your message, which text you could provide by sending a CustomEvent with a message property that will simply take a String. It wouldn't take too much work to create your own Alert class.It would sit on top of your App , you could toggle visibility when receiving a CustomEvent and have a Close button to hide it.


You should be able to call your AS3 class within script tags , other than that I'll leave a more detailed answer to Flex experts. I'm not sure if you can add a Sprite directly into Flex , for all I remember an object in Flex must inherit from UIComponent in order to be added to the stage but check with the other guys here, I haven't used Flex in quite some time...

<mx:Script>
   import org.com.cldAS;

   public cld:cldAS = new cldAS();
</mx:Script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文