flash as 3与asp 在线拍照实例代码
flash as 3与asp教程 在线拍照实例代码
system.usecodepage = true;
import flash.display.bitmapdata;
//============摄像头初始化=============
var _cam:camera = camera.get();
_cam.setmode(160, 120, 12, true);
_video.attachvideo(_cam);
//==========收集图像数据并显示========
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;
//================输出图像==============
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 = 0xffffff;
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;
};
//===================接收图片数据========
var bmpdatashow_func:function = function (_l易做图dvars) {
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);
};
//============发送图像数据并接收========
var bmp_l易做图dvars = new loadvars();
bmp_lv.onload = function(success:boolean):void {
if (success && this.suc_asp == "刷新成功!") {
bmpdatashow_func(this);
show_txt.text = "数据发送成功!";
nameshow_func();
}
};
var bmp_func:function = function () {
var bmp_array:array = new array();
for (var x:number = 159; x>=0; x--) {
var bmpy_array:array = new array();
for (var y:number = 119; y>=0; y--) {
bmpy_array.push(_bmp.getpixel(x, y).tostring(16));
}
bmp_array.push(bmpy_array+"|");
}
bmp_lv.name = in_txt.text;
bmp_lv.bmp_data = bmp_array;
show_txt.text = "正在发送数据,请稍等......";
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 = "请输入您的姓名!";
settimeout(function () {
show_txt.text = "";
}, 2000);
}
};
//=============列表添加=========
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.target.selectedindex);
select_func(name_array[evt.target.selectedindex]);
};
//===============名字显示================
var name_l易做图dvars = 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();
//===============图像查询===================
var showbmp_lv:loadvars = new loadvars();
showbmp_lv.onload = function(success) {
if (success) {
bmpdatashow_func(this);
show_txt.text = "数据接收成功!";
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 = "正在接收数据,请稍等......";
};
select_btn.onrelease = function() {
select_func(in_txt.text);
};
//============删除===================
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 = "删除失败!";
}
};
var delete_func:function = function () {
if (_txt.text != undefined) {
show_txt.text = "正在删除图片,请稍等......";
delete_lv.name = _txt.text;
delete_lv.sendandload("asp/delete.asp?id="+math.random(), delete_lv, "post");
} else {
show_txt.text = "请选中要删除的图片。";
settimeout(function () {
show_txt.text = "";
}, 3000);
}
};
delete_btn.onrelease = delete_func;
//==============进入管理=====================
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);
};
补充:flash教程,动画技术