Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

FredT

macrumors newbie
Original poster
Mar 28, 2008
18
0
Hi,

I have a problem with my AS3 code. The user can type their desired width and height for the video in two boxes and hit a button that triggers the updateResolution function. Everything works except for when I redeclare video = new Video() in the updateResolution function, the variables that the user set don't register. If I manually say:

video = new Video(1024,768);

it works fine, but for some reason the vars don't have the same effect...

video = new Video(setWidth, setHeight);

Does anyone have any suggestions? Thanks!!!

Code:
//Initial vars for resolution
var setWidth:int = 800;
var setHeight:int = 600;
 
//Display the webcam feed on the screen
var cam:Camera = Camera.getCamera();
var video:Video = new Video(800, 600);
video.width = 320; //Changing it on the screen only so it fits
video.height = 240; //The actual resolution remains 800x600
cam.setMode(800, 600, 15, true);
video.attachCamera(cam);
stage.addChild(video);
video.x = 320;
 
//updateRes is my button, of course
updateRes.addEventListener(MouseEvent.MOUSE_DOWN, updateResolution);
 
function updateResolution(e:MouseEvent):void{
	setWidth = Number(userWidth.text); //userWidth and userHeight are the text inputs
	setHeight = Number(userHeight.text);
	cam.setMode(setWidth, setHeight, 15, true); //This works fine with the setWidth/setHeight vars
	stage.removeChild(video);
	video = new Video(setWidth, setHeight); //This does not
	video.width = 320;
	video.height = 240;
	video.attachCamera(cam);
	stage.addChild(video);
	video.x = 320;
}
 
No, because they just change the display size of the video, while the actual resolution (which is actually shown more later when the app takes a snapshot from the webcam) remains.

Does that make sense?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.