简体   繁体   中英

Flash AS3 and webcam: problems with AIR

I'm having some problems getting the Flash AS3 Camera to work correctly. If you could help, much appreciated. I looked at olThe details:

I'm able, when publishing to a SWF, to get the webcam up and running and all works fine, popping up the 'may I access your camera dialog' which returns muted or not.

• First question: is there any way to make it so I can bypass the user permission, that is always grant it? We are running a kiosk app. Will the following method work for an AIR app? https://stackoverflow.com/questions/3266939/flash-grant-access-to-webcam-programmatically-behind-the-scenes

• Second question: as I said, I can get the webcam/Camera hookup to work fine when publishing for SWF in IDE, and in browser. But if I switch the project to publish for AIR and run the air app, or test in the IDE, I don't get the security permissions dialog coming up at all. Nothing. Perhaps the security box is off screen? Is there some way to control the placement? Is there something different about using the webcam from within AIR?

I'm happy to NOT publish to AIR, but to use SWF — simply need to be able to read/write to XML files on local disk and think that AIR only way to do that?

Thanks for any help!

The code:

private function initTracking() : void
    {

        var camW : int = 840;
        var camH : int = 640;

        // Create the camera
        _cam = Camera.getCamera();

        if (_cam == null) 
        { 
            trace("Unable to locate available cameras."); 
            return;
        } 
        else 
        { 
            trace("Found camera: " + _cam.name); 
            _cam.addEventListener(StatusEvent.STATUS, camStatusHandler); 

            _cam.setMode(camW, camH, stage.frameRate);

            // Create a video
            _vid = new Video(camW, camH);
            _vid.attachCamera(_cam);
            trace("camera ", _cam, " attached to video ", _vid);

            // Create the Motion Tracker
            _motionTracker = new MotionTracker(_vid);

            // We flip the input as we want a mirror image
            _motionTracker.flipInput = true;

        }
    }


    private function camStatusHandler(event:StatusEvent):void 
    { 
                trace("camStatusHandler::");

        if (_cam.muted) 
        { 
            trace("Unable to connect to active camera."); 
        } 
        else 
        { 

        trace("able to connect to active camera.");
                addEventListener(Event.ENTER_FRAME, onEnterFrameHandler, false,0,true);

        } 
        // Remove the status event listener. 
        _cam.removeEventListener(StatusEvent.STATUS, camStatusHandler); 
    }

If you publish as AIR, there is no security dialog (the security box for swfs is there to stop 'hackers' gaining control of a users webcam without their knowledge).

If your code works in a swf, it should also work in an AIR app without needing any changes - assuming AIR is running on the desktop and not a mobile device?

If you are not seeing the webcam output when you publish as an AIR app, post the relevant code.

Edit:

The StatusEvent.STATUS event does not occur with AIR apps - it fires when user closes security dialog - hence camStatusHandler never gets called.

So remove camStatusHandler function completely and also this line:

_cam.addEventListener(StatusEvent.STATUS, camStatusHandler);

And add important code from camStatusHandler to the end of initTracking:

addEventListener(Event.ENTER_FRAME, onEnterFrameHandler, false,0,true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM