Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7687887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:48:02+00:00 2026-05-31T19:48:02+00:00

I am using ActionScript 3 to capture image via users webcam in one of

  • 0

I am using ActionScript 3 to capture image via users webcam in one of my Asp.net Page. Here is the code i am using

   package 
{
    import flash.display.Sprite;
    import flash.media.Camera;
    import flash.media.Video;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.events.MouseEvent;
    import flash.net.FileReference;
    import flash.utils.ByteArray;
    import com.adobe.images.JPGEncoder;
    import com.dynamicflash.util.Base64;

     import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;





    public class Main extends Sprite
    {
        private var camera:Camera = Camera.getCamera();
        private var video:Video = new Video();
        private var bmd:BitmapData = new BitmapData(320,240);
        private var bmp:Bitmap;
        private var fileReference:FileReference = new FileReference();
        private var byteArray:ByteArray;
        private var jpg:JPGEncoder = new JPGEncoder();
        private var _uploadPath:String = "/Upload.aspx";







        public function Main():void
        {

            saveButton.visible = false;
            discardButton.visible = false;

            saveButton.addEventListener(MouseEvent.MOUSE_UP, saveImage);
            discardButton.addEventListener(MouseEvent.MOUSE_UP, discard);
            capture.addEventListener(MouseEvent.MOUSE_UP, captureImage);

            if (camera != null)
            {

                video.smoothing = true;
                video.attachCamera(camera);
                video.x = 140;
                video.y = 40;
                addChild(video);
            }
            else
            {
                trace("No Camera Detected");
            }
        }

        private function captureImage(e:MouseEvent):void
        {
            bmd.draw(video);
            bmp = new Bitmap(bmd);
            bmp.x = 140;
            bmp.y = 40;
            addChild(bmp);

            capture.visible = false;
            saveButton.visible = true;
            discardButton.visible = true;
        }

        private function saveImage(e:MouseEvent):void
        {
            byteArray = jpg.encode(bmd);
            var base64Bytes:String = Base64.encodeByteArray(byteArray);
            var vars:URLVariables = new URLVariables();
            vars.imageData = base64Bytes;

            // and send it over the wire via HTTP POST
            var url:URLRequest = new URLRequest(_uploadPath);
            url.data = vars;
            url.method = URLRequestMethod.POST;

            var loader:URLLoader = new URLLoader();
            loader.load(url);



            //fileReference.save(byteArray, "Image.jpg");


            removeChild(bmp);
            saveButton.visible = false;
            discardButton.visible = false;
            capture.visible = true;
        }

        private function discard(e:MouseEvent):void
        {
            removeChild(bmp);
            saveButton.visible = false;
            discardButton.visible = false;
            capture.visible = true;
        }
    }
}

Here the image is saved using file reference, which prompts the user to save. However i want that the image should be sent to asp.net page or server, so that i can get the image and save it to the database so can you guys guide me as to how i could proceed ,
Any suggestions are highly appreciated.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:48:03+00:00Added an answer on May 31, 2026 at 7:48 pm

    you can do something like:

    (untested code)

    import flash.events.Event;
    import flash.events.IOErrorEvent;
    
    private function saveImage(e:MouseEvent):void
    {
        byteArray = jpg.encode(bmd);
    
        //Get the URLRequest ready
        var jpgURLRequest:URLRequest = 
            new URLRequest("http://site.com/upload.aspx?args=here");        
        jpgURLRequest.requestHeaders.push(
            new URLRequestHeader("Content-type", "application/octet-stream"));
        jpgURLRequest.method = URLRequestMethod.POST;
    
        //Add jpg byte array to URL request
        jpgURLRequest.data = byteArray;
    
        //Get the URLLoader ready
        sendJPGLoader = new URLLoader(jpgURLRequest);
        sendJPGLoader.dataFormat = URLLoaderDataFormat.BINARY;
        sendJPGLoader.addEventListener(Event.COMPLETE, uploadJPGComplete);
        sendJPGLoader.addEventListener(IOErrorEvent.IO_ERROR, uploadJPGIOError);
    
        //Try to send image
        sendJPGLoader.load(jpgURLRequest);
    
    }
    

    And your event handlers:

    private function uploadJPGComplete(evt:Event):void {
        //Handle server response via evt.target.data
    
        //Optionally do your stuff after uploading, if it makes sense here
        removeChild(bmp);
        saveButton.visible = false;
        discardButton.visible = false;
        capture.visible = true;
    }
    
    private function uploadJPGIOError(evt:IOErrorEvent):void {
        //Something went wrong while trying to talk to the server   
    }
    

    Of course you’ll have to do the server half as well, but this should do what you need on the Flash client’s end, with possibly some minor tweeking involved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ActionScript 3.0 to capture image from users webcam ,It is working
I am creating a textbutton using actionscript. the code is given below. public function
I'm using Actionscript 3, and am building an image viewer. So far, I have
How do I pass arguments using ActionScript's event-listener? I have code, as given below,
How do you trigger a javascript function using actionscript in flash? The goal is
Hi when I add a new component using Actionscript I want it to fade
I've been developing stuff using ActionScript since AS2,and when AS3 was released i had
How do you reference a bitmap on the stage in flash using actionscript 3?
I'm having trouble sending out a simple HTTP request using Actionscript 3's Socket() object.
Is it possible, using actionscript 3 to disable the right click menu? Any help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.