Flash as 3 and asp online photo taking instance code

Source: Internet
Author: User

Flash as 3 and asp tutorial online photo taking instance code

System. usecodepage = true;
Import flash. display. bitmapdata;
// ================ Camera initialization ==================
Var _ cam: camera = camera. get ();
_ Cam. setmode (160,120, 12, true );
_ Video. attachvideo (_ cam );
// ============ Collect image data and display ========
Var photo_mc: movieclip = this. createemptymovieclip ("photo_mc", 2 );
Photo_mc. _ x = 200;
Photo_mc. _ y = 10;
Var _ bmp: bitmapdata = new bitmapdata (160,120, true, 0xfff000 );
Var cam_func: function = function (){
_ Bmp. draw (_ video );
Photo_mc.attachbitmap (_ bmp, 3, "always", true );
};
Camera_btn.onrelease = cam_func;
// ======================== Output image ================
Var out_mc: movieclip = this. createemptymovieclip ("out_mc", 10 );
Out_mc. _ x = 380;
Out_mc. _ y = 130;
Out_mc. _ yscale =-100;
This. createtextfield ("_ txt", 22, out_mc. _ x + 10, out_mc. _ y-25, 100, 20 );
This. _ txt. textcolor = 0 xffffff;
Var out_func: function = function (_ array: array, name_str: string ){
Var out_bmp: bitmapdata = new bitmapdata (160,120, true );
For (var x: number = _ array. length-1; x> = 0; x --){
For (var y: number = _ array [x]. length-1; y> = 0; y --){
Out_bmp .setpixel (x, y, number ("0x" + _ array [x] [y]);
  }
}
Out_mc.attachbitmap (out_bmp, 11, "always", true );
This. _ txt. text = name_str;
};
// ================================ Receive image data
Var BMP datashow_func: function = function (_ lvoadvars ){
Var out_array: array = new array ();
Var temp_array: array = new array ();
Temp_array = _ lv. data_asp.split ("| ");
For (var d: number = temp_array.length-2; d> = 0; d --){
Var temp2_array: array = new array ();
Temp2_array = temp_array [d]. split (",");
Out_array.push (temp2_array );
}
Out_func (out_array, _ lv. name_asp );
};
// ================ Send image data and receive ========
Var BMP _lvoadvars = new loadvars ();
BMP _lv.onload = function (success: boolean): void {
If (success & this. suc_asp = "refresh successful! "){
BMP datashow_func (this );
Show_txt.text = "data sent successfully! ";
Nameshow_func ();
}
};
Var BMP _func: function = function (){
Var BMP _array: array = new array ();
For (var x: number = 159; x> = 0; x --){
Var BMP y_array: array = new array ();
For (var y: number = 119; y> = 0; y --){
Bmp y_array.push (_ bmp. getpixel (x, y). tostring (16 ));
  }
BMP _array.push (BMP y_array + "| ");
}
BMP _lv.name = in_txt.text;
BMP _lv.bmp _data = BMP _array;
Show_txt.text = "sending data. Please wait ......";
Bmp _lv.sendandload ("asp/bmp. asp? Id = "+ math. random (), BMP _lv," post ");
};
Send_btn.onrelease = function (){
If (in_txt.text! = ""){
BMP _func ();
} Else {
Show_txt.text = "enter your name! ";
Settimeout (function (){
Show_txt.text = "";
},2000 );
}
};
// ================== Add List ============
Var additem_func: function = function (_ array: array ){
Name_list.removeall ();
For (var d: number = 0; d <_ array. length-1; d ++ ){
Name_list.additem (d + 1) + ":" + _ array [d]);
}
};
Name_list.addeventlistener ("change", this );
This. change = function (evt ){
// Trace(evt.tar get. selectedindex );
Select_func(name_arrayincluevt.tar get. selectedindex]);
};
// ====================== Name display ==============================
Var name_lvoadvars = new loadvars ();
Var name_array: array = new array ();
Name_lv.onload = function (success ){
Trace (success );
If (success ){
Name_array = [];
Name_array = this. name_asp.split ("| ");
Additem_func (name_array );
Settimeout (function (){
In_txt.text = "";
Show_txt.text = "";
},1000 );
}
};
Var nameshow_func: function = function (){
Name_lv.load ("asp/showname. asp? Id = "+ math. random ());
};
Nameshow_func ();
// ======================= Image query ==============================
Var showbmp _lv: loadvars = new loadvars ();
Showbmp _lv.onload = function (success ){
If (success ){
BMP datashow_func (this );
Show_txt.text = "data received successfully! ";
Nameshow_func ();
}
};
Var select_func: function = function (name_str: string ){
Showbmp _lv.name = name_str;
Showbmp _lv.sendandload ("asp/selectbmp. asp? Id = "+ math. random (), showbmp _lv," post ");
Show_txt.text = "receiving data. Please wait ......";
};
Select_btn.onrelease = function (){
Select_func (in_txt.text );
};
// ================ Delete =================================
Var delete_lv: loadvars = new loadvars ();
Delete_lv.onload = function (success ){
If (success ){
Show_txt.text = this. suc_asp;
_ Txt. text = "";
Nameshow_func ();
} Else {
Show_txt.text = "deletion failed! ";
}
};
Var delete_func: function = function (){
If (_ txt. text! = Undefined ){
Show_txt.text = "deleting the image. Please wait ......";
Delete_lv.name = _ txt. text;
Delete_lv.sendandload ("asp/delete. asp? Id = "+ math. random (), delete_lv," post ");
} Else {
Show_txt.text = "select the image to be deleted. ";
Settimeout (function (){
Show_txt.text = "";
},3000 );
}
};
Delete_btn.onrelease = delete_func;
// ==================== Go to management =============================
Delete_btn.enabled = false;
This. onkeydown = function (){
If (key. getcode () = 13 & in_txt.text = "ing "){
Delete_btn.enabled = true;
}
};
In_txt.onsetfocus = function (){
Key. addlistener (this. _ parent );
};
In_txt.onkillfocus = function (){
Key. removelistener (this. _ parent );
};

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.