Using (web) cam from loaded swf file in AIR application
Copy link to clipboard
Copied
Hi everyone,
I am currently working on a project where a host application (AIR 3.4) loads different client applications which were created as individual .swf files to enable different interactivity without touching the host.
For example there is a video player application as client and a client which loads RSS feeds from the net and so on. Now I want to create a client that can capture footage from an installed webcam.
I've written a short test and loaded it into my host application and there I get no feed from the camera. When I test the client on it's own I have no problem with displaying the video feed in the holder movieclip. Is there an issue I've been missing?
The code to the client is something like that:
private function fnc_addedToStage(evt: Event): void{
fnc_dispatchErrorMessage(this.name + ": Has beend added to stage");
// clean up the EventListener
this.removeEventListener(Event.ADDED_TO_STAGE, fnc_addedToStage);
// setup the video window
var video = new Video();
video.smoothing = false;
video.width = outputWindow.width;
video.height = outputWindow.height;
// add it to the outputWindow holder sprite
outputWindow.addChild(video);
// setup the camera
var camera = Camera.getCamera();
// width, height, fps && maximum quality
camera.setMode(320, 240, 30);
camera.setQuality(0, 100);
camera.addEventListener(StatusEvent.STATUS, statusHandler);
fnc_dispatchErrorMessage("Camera: " + Camera.isSupported);
// attach the camera
video.attachCamera(camera);
}
fnc_dispatchErrorMessage is a wrapper function to send my trace statements to a log file in the host application. outputWindow is a movie clip on the stage which functions as a content holder.
The loading component of the host looks like that:
private function fnc_pageLoaded(evt: Event): void{
// clean up the eventListener
pageSWFLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, fnc_pageLoaded);
// casting it into the container movieClip, so that it's functions can be accessed
//pageContainer = new MovieClip();
pageContainer = MovieClip(pageSWFLoader.contentLoaderInfo.content);
// setting up the dimensions and position loaded from the xml file
pageContainer.width = Number(pageConfig.fnc_getSingleElement("pageWidth"));
pageContainer.height = Number(pageConfig.fnc_getSingleElement("pageHeight"));
pageContainer.x = Number(pageConfig.fnc_getSingleElement("pagePositionX"));
pageContainer.y = Number(pageConfig.fnc_getSingleElement("pagePositionY"));
pageContainer.addEventListener("calledError", fnc_pageContainerError);
// add it to the display list
addChild(pageContainer);
// and so on...
fnc_getSingleElement reads a value from a configuration xml file.
Any help would be great, cause I'm totally stuck at the moment. And searching in the AS3 API and Google didn't get me any results.
Thank you.

Copy link to clipboard
Copied
Is the addedToStage handler executed? When running the client at its own things are on stage when start running. Which should be the difference betweeen loading them first.
Therfor I often use code like this in my client classes
if (stage == null){
this.addEventHandler(Event.AddedToStage, onATS)
}else{
onATS();
}
Copy link to clipboard
Copied
Thanks for your reply,
Yes, the addedToStage handler is executed every time. I set my host application up to work exactly with that behaviour. There are several events going from client to host to help the communication inside the the application. I can't get behind the reason why it won't work.
I made a case where I created a camera instance inside the host application and passed it over to the client via
client.setupFunction(inArg: arg, sendCamera: Camera);
That works. But I also need a microphone, and I can't get the mic working over with the same technique. And also I'd prefer to have it all in the client, cause I designed the application model to work exactly in that fashion.
I guess it's a secruity sandboxing problem, but I can't find any documentation on this issue.
Thanks, maybe another solution can be found here. 😉

