0
votes

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 

        }
    }                   

}
  }
2

2 Answers

0
votes

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

0
votes

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>