Actionscript problem with resizing video object resolution

Discussion in 'Web Design and Development' started by FredT, Jan 11, 2009.

  1. FredT macrumors newbie

    Joined:
    Mar 28, 2008
    #1
    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;
    }
    
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Aren't the second two lines undoing the first line?
     
  3. FredT thread starter macrumors newbie

    Joined:
    Mar 28, 2008
    #3
    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?
     

Share This Page