[此文来源于互联网,牛C网只负责收集整理]
无聊的时候就来把美女分割![由讨厌原创==>无聊+乱整]
无聊的时候就来把美女分割![由讨厌原创==>无聊+乱整]
能把一张图片分割成若干份,份数由输入数字自由决定。分割后自动随机打乱位置,可以拖到,拖到到正确位置自动吸附,并不允许再抛动。基本能算一个拼图游戏的雏形了吧。但整到这里就不想整了。能用右键加载自己的图片。以下是无聊的代码:
分割图片.rar
import flash.net.FileReference;
import flash.display.BitmapData;
import flash.geom.Matrix;
/////////////////////////////////
var img_bmp:BitmapData = new BitmapData(mc._width, mc._height);
var txt_fmt:TextFormat = new TextFormat();
txt_fmt.color = 0xff00ff;
txt_fmt.size = 22;
txt_fmt.font = "华文新魏";
/////////////////////
for (var d:Number = 2; d>0; d--) {
this.createTextField("wh_txt" d, 9000 d, d*100, 20, 50, 26);
this["wh_txt" d].setNewTextFormat(txt_fmt);
this["wh_txt" d].border = true;
this["wh_txt" d].input = true;
this["wh_txt" d].type = "input";
this["wh_txt" d].maxChars = 1;
this["wh_txt" d].restrict("0-9");
this["wh_txt" d].background = true;
this["wh_txt" d].borderColor = 0xff9900;
this["wh_txt" d].backgroundColor = 0x33cccc;
}
Selection.setFocus("wh_txt1");
//////////////////
wh_txt1.onChanged = wh_txt2.onChanged=function () {
if (wh_txt1.text == "") {
Selection.setFocus("wh_txt1");
} else if (wh_txt2.text == "") {
Selection.setFocus("wh_txt2");
} else {
fenge_func(wh_txt1.text, wh_txt2.text);
}
};
////////////////////////
var xwpos:Number = 0;
var yhpos:Number = 0;
function fuwei_func() {
for (var d:Number = xwpos-1; d>=0; d--) {
for (var c:Number = yhpos-1; c>=0; c--) {
this["pic_mc" d c].removeMovieClip();
}
}
}
//////
function fenge_func(xw:Number, yh:Number) {
fuwei_func();
xwpos = xw;
yhpos = yh;
img_bmp.draw(mc, new Matrix());
var xy_array:Array = new Array();
var b_num:Number = new Number();
////////////////
for (var d:Number = xw-1; d>=0; d--) {
for (var c:Number = yh-1; c>=0; c--) {
this.createEmptyMovieClip("pic_mc" d c, 200 d "" c);
this["pic_mc" d c].lineStyle(1, 0xfff000, 100);
this["pic_mc" d c].beginBitmapFill(img_bmp, new Matrix(), false);
this["pic_mc" d c].moveTo(d*Stage.width/xw, c*Stage.height/yh);
this["pic_mc" d c].lineTo((d 1)*Stage.width/xw, c*Stage.height/yh);
this["pic_mc" d c].lineTo((d 1)*Stage.width/xw, (c 1)*Stage.height/yh);
this["pic_mc" d c].lineTo(d*Stage.width/xw, (c 1)*Stage.height/yh);
this["pic_mc" d c].lineTo(d*Stage.width/xw, c*Stage.height/yh);
this["pic_mc" d c].endFill();
this["pic_mc" d c].obj = new Object();
this["pic_mc" d c].obj = this["pic_mc" d c].getBounds(_root);
this["pic_mc" d c].xpos = this["pic_mc" d c].obj.xMin;
this["pic_mc" d c].ypos = this["pic_mc" d c].obj.yMin;
////////////////
var xy2_array:Array = new Array();
xy2_array.push(this["pic_mc" d c].obj.xMin, this["pic_mc" d c].obj.yMin);
xy_array.push(xy2_array);
this["pic_mc" d c].id = d "" c;
//////////////////
this["pic_mc" d c].onPress = function() {
b_num = this.id;
this.swapDepths(this._parent.getNextHighestDepth());
this.startDrag();
};
}
}
////////////////
for (var d:Number = xw-1; d>=0; d--) {
for (var c:Number = yh-1; c>=0; c--) {
num = Math.floor(Math.random()*xy_array.length);
this["pic_mc" d c]._x = xy_array[num][0]-this["pic_mc" d c].xpos;
this["pic_mc" d c]._y = xy_array[num][1]-this["pic_mc" d c].ypos;
xy_array.splice(num, 1);
}
}
//////////////////
onMouseUp = function () {
stopDrag();
if (this["pic_mc" b_num].hitTest(this["pic_mc" b_num].xpos this["pic_mc" b_num]._width/2, this["pic_mc" b_num].ypos this["pic_mc" b_num]._height/2)) {
this["pic_mc" b_num]._x = 0;
this["pic_mc" b_num]._y = 0;
this["pic_mc" b_num].swapDepths(-this["pic_mc" b_num].getDepth());
this["pic_mc" b_num].enabled = false;
}
};
////////////
mc._visible = false;
}
/////////////////////////////
var listener:Object = new Object();
////////
var loadpic:MovieClipLoader = new MovieClipLoader();
listener.onLoadInit = function(target:MovieClip) {
target._width = Stage.width;
target._height = Stage.height;
fuwei_func();
wh_txt1.text = "";
wh_txt2.text = "";
Selection.setFocus("wh_txt1");
};
loadpic.addListener(listener);
/////////////////
var fileRef:FileReference = new FileReference();
var allTypes:Array = [];
var 浏览类型:Object = new Object();
浏览类型.description = "浏览类型(*.jpg)";
浏览类型.extension = "*.jpg";
allTypes.push(浏览类型);
listener.onSelect = function(file:FileReference) {
loadpic.loadClip("/" file.name, mc);
};
fileRef.addListener(listener);
/////////////////////////
var pic_menu:ContextMenu = new ContextMenu();
function browse_func() {
fileRef.browse(allTypes);
}
pic_menu.hideBuiltInItems();
var loadpic_menu:ContextMenuItem = new ContextMenuItem("加载新图片", browse_func);
pic_menu.customItems.push(loadpic_menu);
_root.menu = pic_menu;
swf. fla 下载:import flash.display.BitmapData;
import flash.geom.Matrix;
/////////////////////////////////
var img_bmp:BitmapData = new BitmapData(mc._width, mc._height);
var txt_fmt:TextFormat = new TextFormat();
txt_fmt.color = 0xff00ff;
txt_fmt.size = 22;
txt_fmt.font = "华文新魏";
/////////////////////
for (var d:Number = 2; d>0; d--) {
this.createTextField("wh_txt" d, 9000 d, d*100, 20, 50, 26);
this["wh_txt" d].setNewTextFormat(txt_fmt);
this["wh_txt" d].border = true;
this["wh_txt" d].input = true;
this["wh_txt" d].type = "input";
this["wh_txt" d].maxChars = 1;
this["wh_txt" d].restrict("0-9");
this["wh_txt" d].background = true;
this["wh_txt" d].borderColor = 0xff9900;
this["wh_txt" d].backgroundColor = 0x33cccc;
}
Selection.setFocus("wh_txt1");
//////////////////
wh_txt1.onChanged = wh_txt2.onChanged=function () {
if (wh_txt1.text == "") {
Selection.setFocus("wh_txt1");
} else if (wh_txt2.text == "") {
Selection.setFocus("wh_txt2");
} else {
fenge_func(wh_txt1.text, wh_txt2.text);
}
};
////////////////////////
var xwpos:Number = 0;
var yhpos:Number = 0;
function fuwei_func() {
for (var d:Number = xwpos-1; d>=0; d--) {
for (var c:Number = yhpos-1; c>=0; c--) {
this["pic_mc" d c].removeMovieClip();
}
}
}
//////
function fenge_func(xw:Number, yh:Number) {
fuwei_func();
xwpos = xw;
yhpos = yh;
img_bmp.draw(mc, new Matrix());
var xy_array:Array = new Array();
var b_num:Number = new Number();
////////////////
for (var d:Number = xw-1; d>=0; d--) {
for (var c:Number = yh-1; c>=0; c--) {
this.createEmptyMovieClip("pic_mc" d c, 200 d "" c);
this["pic_mc" d c].lineStyle(1, 0xfff000, 100);
this["pic_mc" d c].beginBitmapFill(img_bmp, new Matrix(), false);
this["pic_mc" d c].moveTo(d*Stage.width/xw, c*Stage.height/yh);
this["pic_mc" d c].lineTo((d 1)*Stage.width/xw, c*Stage.height/yh);
this["pic_mc" d c].lineTo((d 1)*Stage.width/xw, (c 1)*Stage.height/yh);
this["pic_mc" d c].lineTo(d*Stage.width/xw, (c 1)*Stage.height/yh);
this["pic_mc" d c].lineTo(d*Stage.width/xw, c*Stage.height/yh);
this["pic_mc" d c].endFill();
this["pic_mc" d c].obj = new Object();
this["pic_mc" d c].obj = this["pic_mc" d c].getBounds(_root);
this["pic_mc" d c].xpos = this["pic_mc" d c].obj.xMin;
this["pic_mc" d c].ypos = this["pic_mc" d c].obj.yMin;
////////////////
var xy2_array:Array = new Array();
xy2_array.push(this["pic_mc" d c].obj.xMin, this["pic_mc" d c].obj.yMin);
xy_array.push(xy2_array);
this["pic_mc" d c].id = d "" c;
//////////////////
this["pic_mc" d c].onPress = function() {
b_num = this.id;
this.swapDepths(this._parent.getNextHighestDepth());
this.startDrag();
};
}
}
////////////////
for (var d:Number = xw-1; d>=0; d--) {
for (var c:Number = yh-1; c>=0; c--) {
num = Math.floor(Math.random()*xy_array.length);
this["pic_mc" d c]._x = xy_array[num][0]-this["pic_mc" d c].xpos;
this["pic_mc" d c]._y = xy_array[num][1]-this["pic_mc" d c].ypos;
xy_array.splice(num, 1);
}
}
//////////////////
onMouseUp = function () {
stopDrag();
if (this["pic_mc" b_num].hitTest(this["pic_mc" b_num].xpos this["pic_mc" b_num]._width/2, this["pic_mc" b_num].ypos this["pic_mc" b_num]._height/2)) {
this["pic_mc" b_num]._x = 0;
this["pic_mc" b_num]._y = 0;
this["pic_mc" b_num].swapDepths(-this["pic_mc" b_num].getDepth());
this["pic_mc" b_num].enabled = false;
}
};
////////////
mc._visible = false;
}
/////////////////////////////
var listener:Object = new Object();
////////
var loadpic:MovieClipLoader = new MovieClipLoader();
listener.onLoadInit = function(target:MovieClip) {
target._width = Stage.width;
target._height = Stage.height;
fuwei_func();
wh_txt1.text = "";
wh_txt2.text = "";
Selection.setFocus("wh_txt1");
};
loadpic.addListener(listener);
/////////////////
var fileRef:FileReference = new FileReference();
var allTypes:Array = [];
var 浏览类型:Object = new Object();
浏览类型.description = "浏览类型(*.jpg)";
浏览类型.extension = "*.jpg";
allTypes.push(浏览类型);
listener.onSelect = function(file:FileReference) {
loadpic.loadClip("/" file.name, mc);
};
fileRef.addListener(listener);
/////////////////////////
var pic_menu:ContextMenu = new ContextMenu();
function browse_func() {
fileRef.browse(allTypes);
}
pic_menu.hideBuiltInItems();
var loadpic_menu:ContextMenuItem = new ContextMenuItem("加载新图片", browse_func);
pic_menu.customItems.push(loadpic_menu);
_root.menu = pic_menu;
分割图片.rar作者:gdgzboy@牛C网
地址:http://www.niuc.net/post/1997/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
牛C网推荐您再看看以下日志:
Flash教程-纯AS制作简单的MP3播放器
Flash AS深入了解setInterval方法的几个重点
数学课件-用Flash AS推导三角形面积
用Flash AS3制作常见的柄图动画效果
Adobe Flex 2 入门教程之RIA概述
Flash AS2 事件处理机制
Flash制作的XML图片加载示例(带分页效果)
Flash问答-一个简单的字母顺序变化效果
ASP FLASH制做上下首后页的按钮
Adobe flash cs3 ActionScript 3.0入门
Flash教程-纯AS制作简单的MP3播放器
Flash AS深入了解setInterval方法的几个重点
数学课件-用Flash AS推导三角形面积
用Flash AS3制作常见的柄图动画效果
Adobe Flex 2 入门教程之RIA概述
Flash AS2 事件处理机制
Flash制作的XML图片加载示例(带分页效果)
Flash问答-一个简单的字母顺序变化效果
ASP FLASH制做上下首后页的按钮
Adobe flash cs3 ActionScript 3.0入门
A simple FLEX VIDEO SOURCE
学习Flash8中的setTimeout函数的用法





