AS3 Multiple Webcams not showing 3rd webcam - actionscript-3

Hi I'm trying to create a simple AIR 3 application that displays 3 Webcams on the stage. For some reason the 3rd webcam doesn't want to show, it doesn't even turn on the LED indicator on the webcam.
I have tried multiple webcams eg. microsoft, logitech, built in....
The following code doesn't work:
var videoWidth:int = 1000 / totalCols;
var videoHeight:int = 800 / totalRows;
for (var i:int = 0; i < Math.min(Camera.names.length, totalRows * totalCols); i++) {
var currRow:int = Math.floor(i / totalCols);
var currCol:int = i % totalCols;
var video:Video = new Video(videoWidth, videoHeight);
var cam:Camera = Camera.getCamera(i.toString());
if (cam) {
cam.setMode(videoWidth, videoHeight, 30);
video.attachCamera(cam);
video.x = currCol * videoWidth;
video.y = currRow * videoHeight;
StageObj.addChild(video);
}
}
Neither does this:
//camera settings
track_cam = new Camera();
track_cam = Camera.getCamera("1");
track_cam.setMotionLevel(100);
track_cam.setQuality(0, 100);
track_cam.setMode(1920, 1080, 30);
track_feed = new Video();
track_feed.width = track_cam.width;
track_feed.height = track_cam.height;
track_feed.smoothing = true;
track_feed.attachCamera(track_cam);
StageObj.addChild(track_feed);
player_one_cam = new Camera();
player_one_cam = Camera.getCamera("2");
player_one_cam.setMotionLevel(100);
player_one_cam.setQuality(0, 100);
player_one_cam.setMode(200, 200, 30);
player_one_feed = new Video();
player_one_feed.width = player_one_cam.width;
player_one_feed.height = player_one_cam.height;
player_one_feed.smoothing = true;
player_one_feed.attachCamera(player_one_cam);
StageObj.addChild(player_one_feed);
player_one_feed.x = 500;
player_one_feed.y = 500;
player_two_cam = new Camera();
player_two_cam = Camera.getCamera("0");
player_two_cam.setMotionLevel(100);
player_two_cam.setQuality(0, 100);
player_two_cam.setMode(200, 200, 30);
player_two_feed = new Video();
player_two_feed.width = player_two_cam.width;
player_two_feed.height = player_two_cam.height;
player_two_feed.smoothing = true;
player_two_feed.attachCamera(player_two_cam);
StageObj.addChild(player_two_feed);
Is there a limit on the amount of webcams you can use in AS3?

It seems that I ran out of USB Bandwidth, when using usb 3 on a seperate machine it started working.

Looks like it should work from the docs:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()
name:String (default = null) — Specifies which camera to get, as
determined from the array returned by the names property. For most
applications, get the default camera by omitting this parameter. To
specify a value for this parameter, use the string representation of
the zero-based index position within the Camera.names array. For
example, to specify the third camera in the array, use
Camera.getCamera("2").

Related

Randomising array coordinates with no duplicates AS3

very new to this kind of thing so please bear with me.
So basically I have 4 buttons that I have put to the stage using the Actions panel. They all have set coordinates so every time I run my game, they are in the same place.
Now here's my issue, I want these buttons to randomise their positions using those coordinates, but I often get duplicates, meaning one button is on top of another.
Here is my code so far
var coordArray : Array = [
new Point(44,420),
new Point(270,420),
new Point(44,550),
new Point(270,550),
];
var pointRange:Number = 4;
var randomPoint:int = Math.random()*pointRange;
answerButtons.x = coordArray[randomPoint].x;
answerButtons.y = coordArray[randomPoint].y;
var pointRange_2:Number = 4;
var randomPoint_2:int = Math.random()*pointRange_2;
answerButtons_2.x = coordArray[randomPoint_2].x;
answerButtons_2.y = coordArray[randomPoint_2].y;
var pointRange_3:Number = 4;
var randomPoint_3:int = Math.random()*pointRange_3;
answerButtons_3.x = coordArray[randomPoint_3].x;
answerButtons_3.y = coordArray[randomPoint_3].y;
var pointRange_4:Number = 4;
var randomPoint_4:int = Math.random()*pointRange_4;
answerButtons_4.x = coordArray[randomPoint_4].x;
answerButtons_4.y = coordArray[randomPoint_4].y;
I have googled this profusely and I keep getting answers to do with the splice and shift methods. Is this the type of thing I need? I'm assuming I need a function that removes a point from the array after it is used.
Cheers.
Just remove the coordinate from the list when you pick it randomly using splice:
var coordinates:Vector.<Point> = new <Point>[
new Point(44, 420),
new Point(270, 420),
new Point(44, 550),
new Point(270, 550)
];
function positionAtRandomCoordinate(object:DisplayObject):void {
var index:int = Math.random() * coordinates.length;
var coordinate:Point = coordinates.splice(index, 1)[0];
object.x = coordinate.x;
object.y = coordinate.y;
}
positionAtRandomCoordinate(answerButtons);
positionAtRandomCoordinate(answerButtons_2);
positionAtRandomCoordinate(answerButtons_3);
positionAtRandomCoordinate(answerButtons_4);

Using text as a mask to add a gradient to the text in AS3

I want to apply a gradient to my text in Flash Develop and read that using a mask is the easiest way. Problem is that I can not get it to work. I tried to create a mask with just the textField and by adding it to a sprite, neither work.
Another strange thing is that the textmask will function as a mask for start title if I reverse them like:
starttitle.mask =textmask
When I try the code below nothing displays.
var format2:TextFormat = new TextFormat();
format2.size = 40;
format2.font = "Times New Roman";
format2.bold = true
starttitle = new TextField;
starttitle.defaultTextFormat = format2;
starttitle.text = "Memory Circles";
starttitle.textColor = 0xFF0000
starttitle.autoSize = "center";
starttitle.background = false;
starttitle.backgroundColor = 0xFF4242;
starttitle.x = (300 - starttitle.width * .5);
starttitle.y = (150 - starttitle.height * .5);
starttitle.mouseEnabled = false;
addChild(starttitle)
var textmask:Shape = new Shape
var fillType:String = GradientType.LINEAR;
var colors:Array = [0xFF0000, 0];
var alphas:Array = [1, 1];
var ratios:Array = [0, 255];
var gradientBoxMatrix:Matrix = new Matrix();
gradientBoxMatrix.createGradientBox(50,100,45,0,0);
var spreadMethod:String = SpreadMethod.REPEAT;
textmask.graphics.beginGradientFill(fillType, colors, alphas, ratios,
gradientBoxMatrix, spreadMethod);
textmask.graphics.drawRect(200,100,300,100)
addChild(textmask)
textmask.mask =starttitle
I read something about the font needing to be embedded but I'm using Times New Roman and thought this would be embedded. Also other fonts don't work.
Try to use bitmap caching on starttitle and textmask:
starttitle.cacheAsBitmap=true;
textmask.cacheAsBitmap=true;

How to setup Starling to use full screen iphone4 and iphone5

I am considering updating my app to take advantage of iphone5's bigger screen but not sure how to achieve this is as3.
I have tried a few suggestions online however unable to get them working. The app works and looks fine with no modification but just letterboxes top and bottom.
This is my code:
var stageWidth:int = Constants.STAGEWIDTH; // Hardcoded to 320
var stageHeight:int = Constants.STAGEHEIGHT; // Hardcoded to 480
var screenWidth:int = stage.fullScreenWidth;
var screenHeight:int = stage.fullScreenHeight;
Constants.FULLSCREENWIDTH = stage.fullScreenWidth;
Constants.FULLSCREENHEIGHT = stage.fullScreenHeight;
var iOS:Boolean = Capabilities.manufacturer.indexOf("iOS") != -1;
Starling.multitouchEnabled = false;
Starling.handleLostContext = true;
var viewPort:Rectangle = new Rectangle(0, 0, stage.fullScreenWidth, stage.fullScreenHeight);
var startupImage:Sprite = createStartupImage(viewPort, screenWidth > 320);
Many thanks!
Add a launch image named Default-568h#2x.png to the package. The resolution of this launch image should be 1136*640 pixels. In case you are already using a namespace schema for your launch images, you can just append ”-568h#2x” to the namespace schema.
taken from
http://blogs.adobe.com/airodynamics/2012/11/07/deploying-air-apps-on-iphone-5/
also, stageWidth on starling will be 568 now, not 480 like in 3.5" screens
try to hardcode this now.
var screenWidth:int = 640;
var screenHeight:int = 1136;
var viewPort:Rectangle = new Rectangle(0, 0, screenWidth, screenHeight)
starling = new Starling(Game, stage, viewPort);
starling.stage.stageWidth = 320;
starling.stage.stageHeight = 568;
If this works, it means that you get wrong stageWith and stageHeight from stage.stageWidth.
here you can see how to correctly get stageView and stageHeight but that is different topic
http://forums.adobe.com/message/3712344

as3 text-wrap problems, firefox, mac

So, I've built a little site for a client that doesn't seem to have any problems for me. I post it, and my client reports to me that some of the text is being clipped off in the text fields. I try to recreate the problem on my pc with chrome and firefox, but everything works fine. But he sends me screenshots from his mac with firefox, and sure enough they are being clipped. He claims its only fire-fox, and it is not a factor of window size. so here are the images to show whats going on:
Further most right words should be "Alabama" & "growing"
and here is the code that produces that text (descTextNew is the culprit here):
nameText.text = names[elementNumber];
nameText.autoSize = "center";
nameText.x = object.x + (.5 * videoWidth) - (.5 * nameText.width);
nameText.y = object.y + videoHeight + 8;
nameText.background = true;
nameText.backgroundColor = 0x000000;
textStyling.color = 0xFFFFFF;
textStyling.size = 20;
textStyling.font = myFont.fontName;
textStyling.letterSpacing = 3;
textStyling.align = "center";
nameText.embedFonts = true;
nameText.setTextFormat(textStyling);
container.addChild(nameText);
descTextNew.text = descArrayContent[elementNumber];
descTextNew.y = object.y + videoHeight + nameText.textHeight + margin - 15;
descTextNew.width = nameText.textWidth + 30;
descTextNew.x = object.x + ( (videoWidth - descTextNew.width) / 2 );
descTextNew.wordWrap = true;
descTextNew.autoSize = "left";
descTextNew.background = true;
descTextNew.backgroundColor = 0x000000;
descTextStyling.color = 0xFFFFFF;
descTextStyling.size = Math.round(11 * 1000/stage.stageWidth);
descTextStyling.font = myFont.fontName;
descTextStyling.letterSpacing = .5;
descTextStyling.align = "left";
descTextNew.setTextFormat(descTextStyling);
container.addChild(descTextNew);
Some of these variables are declared as instance variables prior like this:
var names:Array = new Array();
var nameText:TextField = new TextField();
var textStyling:TextFormat = new TextFormat();
var descTextNew:TextField = new TextField();
var descTextStyling:TextFormat = new TextFormat();
var margin:int = 28;
var videoWidth:int = 267;
var videoHeight:int = 150;
arrays names and descArrayContent have the strings "Paul Rollins, Sr." and "Paul Rollins runs a funeral... " added to them at an index number determined by the variable elementNumber. Also object is the image you see in the pic. don't think its necessary to show you that code.
Here's a link if you want to see it in action:
www.footsoldiers.org/test2/
Any ideas what the hell is going on? I don't know where to start.
Have you tried invalidating the control for redraw manually?
this.invalidateDisplayList();
this.invalidateLayering();
this.invalidateLayoutDirection();
this.invalidateProperties();
this.invalidateSize();
I would try to set the .text property after you have set all the other properties.
So try putting the descTextNew.text = descArrayContent[elementNumber] action on the last line.
If this still doesn't fix your problem, I would recommend to also include the descTextNew.multiline = true property.
Good luck!

augmented reality flartoolkit rotation

I'm trying to do some augmented reality projects with flartoolkit . I can now put simple 3d objects on my marker and it works fine , but I wanna give my project some events that the user can interact with . I'm trying to trace the rotation of the marker. there's a container:DisplayObject3D which my application uses to add the 3d objects , I traced this :"trace(container.rotationZ)" but it's just returning 0 . I studied another AR application's source code and it was using the rotation of it's container object without problem .and I think I should mention that I'm using the exercise file of seb lee delisle papervision3d course from lynda.com . anyone has any experience with flartoolkit? the main functions of my my code is as below:
public function AR_AlchemyBase()
{
super(640,480, false);
cameraParams = FLARParam.getDefaultParam(WIDTH * 0.5, HEIGHT * 0.5);
marker = new FLARCode(16, 16);
marker.loadARPattFromFile(new MarkerPattern());
init();
}
public function init():void
{
video = new Video(WIDTH, HEIGHT);
webCam = Camera.getCamera();
webCam.setMode(WIDTH, HEIGHT, 30);
video.attachCamera(webCam);
video.smoothing = true;
camBitmapData = new BitmapData(WIDTH *0.5, HEIGHT * 0.5,false, 0x000000);
camBitmap = new Bitmap(camBitmapData);
camBitmap.scaleX = camBitmap.scaleY = 2;
addChildAt(camBitmap,0);
raster = new FLARRgbRaster(WIDTH *0.5, HEIGHT * 0.5);
detector = new FLARSingleMarkerDetector(cameraParams, marker, 80);
result = new FLARTransMatResult();
viewport.x = -4;
_camera = new FLARCamera3D(cameraParams);
container = new FLARMarkerNode();
scene.addChild(container);
addSceneObjects();
stage.addEventListener(Event.ENTER_FRAME, enterFrame);
}
//the function to put our objects in
public function addSceneObjects() : void
{
var wmat:WireframeMaterial = new WireframeMaterial(0xff0000, 1, 2);
wmat.doubleSided = true;
var plane : Plane = new Plane(wmat, 80, 80);
container.addChild(plane);
var light:PointLight3D = new PointLight3D();
light.x = 1000;
light.y = 1000;
light.z = -1000;
var fmat:FlatShadeMaterial = new FlatShadeMaterial(light, 0xff22aa, 0x0);
var cube : Cube = new Cube(new MaterialsList({all: fmat}), 40, 40, 40);
cube.z = -20;
container.addChild(cube);
}
public function enterFrame(e:Event):void
{
var scaleMatrix:Matrix = new Matrix();
scaleMatrix.scale(0.5, 0.5);
camBitmapData.draw(video, scaleMatrix);
raster.setBitmapData(camBitmapData);
counter++;
if(counter == 3) counter = 0;
var imageFound : Boolean = false
currentThreshold = threshold+ (((counter%3)-1)*thresholdVariance);
currentThreshold = (currentThreshold>255) ? 255 : (currentThreshold<0) ? 0 : currentThreshold;
imageFound = (detector.detectMarkerLite(raster, currentThreshold) && detector.getConfidence() > 0.5) ;
if(imageFound)
{
detector.getTransformMatrix(result);
container.setTransformMatrix(result);
container.visible = true;
threshold = currentThreshold;
thresholdVariance = 0;
if(onImageFound!=null) onImageFound();
}
else
{
if(counter==2) thresholdVariance +=2;
if(thresholdVariance>128 ) thresholdVariance = 1;
if(onImageLost!=null) onImageLost();
}
singleRender();
}
I might not be able to help with the main problem but If you want users to interact with the models you need to set their materials to be interactive, otherwise they don't receive mouse events. Regarding the rotation...I might be missing something but it's the instances inside the container thar you're applying the rotation to, not the the container itself?
This helped me with getting a simple PV3D example running:
PV3D Tutorial for basic interactivity