AS2 图像分解要转换为 AS3
情况是这样的。我正在 cs5.5 中为项目和页面转换创建一个 flash 网站,我想将背景图像分解为随机片段,然后加载下一帧(在 CS3 中,有一个时间线效果可以执行此操作,但已被删除) CS4+)。我找到了 AS2 脚本来分解图像(使用 Tweener.as V1.33(适用于 AS2)),但有人知道如何让它与 AS3 一起使用吗?感谢
码如下:
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
import caurina.transitions.Tweener;
//
var container:MovieClip = this.createEmptyMovieClip("container_mc", this.getNextHighestDepth());
var bmp:BitmapData = BitmapData.loadBitmap("careca");
var grid:Number = 20;
var rect:MovieClip;
var depth:MovieClip = this;
var spacement:Number = 0;
var count:Number = 0;
var rows:Number = 0;
var a:Number, b:Number, c:Number, d:Number;
var rects:MovieClip = depth.createEmptyMovieClip("rects_mc", depth.getNextHighestDepth());
var pieces:Array = new Array();
//
container.attachBitmap(bmp, container.getNextHighestDepth());
container._visible = false;
//
function init() {
create();
}
function randRange(min:Number, max:Number) {
var randomNum:Number = Math.round(Math.random()*(max-min+1)+(min-.5));
return randomNum;
}
function clearBitmaps() {
rects.swapDepths(0);
rects.removeMovieClip();
}
function create() {
for (a=1; a<=Math.round(container._height/grid); a++) {
drawLine();
rows++;
}
rects._x = Stage.width/2-rects._width/2;
rects._y = Stage.height/2-rects._height/2;
}
function drawLine() {
for (b=0; b<Math.round(container._width/grid); b++) {
rect = rects.createEmptyMovieClip("rect"+String(rows)+String(b)+"_mc", rects.getNextHighestDepth());
bmp[i] = new BitmapData(grid, grid, true);
//
bmp[i].copyPixels(bmp, new Rectangle(grid*b, grid*rows, grid, grid), new Point(0, 0));
rect.attachBitmap(bmp[i], rect.getNextHighestDepth());
rect.initX = (rect._width+spacement)*b;
rect.initY = (rect._height+spacement)*rows;
rect.randomX = randRange(-Stage.width, Stage.width);
rect.randomY = randRange(-Stage.height, Stage.height);
rect.randomRotation = randRange(10, 360);
rect.randomScale = randRange(0, 100);
rect.randomAlpha = 0;
rect.cacheAsBitmap = true;
rect._x = rect.initX;
rect._y = rect.initY;
//
pieces.push(rect);
}
setTimeout(animPieces, 1000);
}
function animPieces() {
for (c=0; c<pieces.length; c++) {
rect = pieces[c];
Tweener.addTween(rect, {_scale:rect.randomScale, _rotation:rect.randomRotation, _x:rect.randomX, _y:rect.randomY, _alpha:0, time:5, transition:"easeOutExpo", onComplete:clearBitmaps});
}
}
//
init()
来源:Lemlinh.com
Here is the situation. I'm creating a flash website in cs5.5 for a project and fora page trasition I would like to explode the background image into random pieces and then load the next frame (In CS3 there was a timeline effect to do this but was removed by cs4+). I have found the AS2 script to explode the image (with Tweener.as V1.33 (for AS2)) but does anyone know how to get it to work with AS3? Thanks
Code follows:
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
import caurina.transitions.Tweener;
//
var container:MovieClip = this.createEmptyMovieClip("container_mc", this.getNextHighestDepth());
var bmp:BitmapData = BitmapData.loadBitmap("careca");
var grid:Number = 20;
var rect:MovieClip;
var depth:MovieClip = this;
var spacement:Number = 0;
var count:Number = 0;
var rows:Number = 0;
var a:Number, b:Number, c:Number, d:Number;
var rects:MovieClip = depth.createEmptyMovieClip("rects_mc", depth.getNextHighestDepth());
var pieces:Array = new Array();
//
container.attachBitmap(bmp, container.getNextHighestDepth());
container._visible = false;
//
function init() {
create();
}
function randRange(min:Number, max:Number) {
var randomNum:Number = Math.round(Math.random()*(max-min+1)+(min-.5));
return randomNum;
}
function clearBitmaps() {
rects.swapDepths(0);
rects.removeMovieClip();
}
function create() {
for (a=1; a<=Math.round(container._height/grid); a++) {
drawLine();
rows++;
}
rects._x = Stage.width/2-rects._width/2;
rects._y = Stage.height/2-rects._height/2;
}
function drawLine() {
for (b=0; b<Math.round(container._width/grid); b++) {
rect = rects.createEmptyMovieClip("rect"+String(rows)+String(b)+"_mc", rects.getNextHighestDepth());
bmp[i] = new BitmapData(grid, grid, true);
//
bmp[i].copyPixels(bmp, new Rectangle(grid*b, grid*rows, grid, grid), new Point(0, 0));
rect.attachBitmap(bmp[i], rect.getNextHighestDepth());
rect.initX = (rect._width+spacement)*b;
rect.initY = (rect._height+spacement)*rows;
rect.randomX = randRange(-Stage.width, Stage.width);
rect.randomY = randRange(-Stage.height, Stage.height);
rect.randomRotation = randRange(10, 360);
rect.randomScale = randRange(0, 100);
rect.randomAlpha = 0;
rect.cacheAsBitmap = true;
rect._x = rect.initX;
rect._y = rect.initY;
//
pieces.push(rect);
}
setTimeout(animPieces, 1000);
}
function animPieces() {
for (c=0; c<pieces.length; c++) {
rect = pieces[c];
Tweener.addTween(rect, {_scale:rect.randomScale, _rotation:rect.randomRotation, _x:rect.randomX, _y:rect.randomY, _alpha:0, time:5, transition:"easeOutExpo", onComplete:clearBitmaps});
}
}
//
init()
Source : Lemlinh.com
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,代码看起来对 AS3 非常友好。当然,您必须进行一些修改,但总的来说您应该不会有问题。
首先,删除属性中的所有下划线(例如从 _x 到 x)。
另外,如果您有一个返回值的函数,您必须声明它返回的变量的类型,即。字符串、数字、布尔...
因此,您的范围函数将如下所示:
下载 Tweener 的 AS3 版本或查看 TweenMax: http://www.greensock.com/tweenmax,只需将 Tweener 代码替换为 TweenMax 即可。很容易做到。
从:
到:
尝试一下。应该比您想象的要容易;)如果您遇到困难或有疑问,请立即开火!
Honestly, the code looks pretty AS3 friendly. Sure, there are modifications you have to implement, but overall you shouldn't have a problem.
First this is delete all the underscores in the properties (eg from _x to x).
Also, if you have a function that returns a value you have to declare the type of variable it returns ie. String, Number, Boolean....
So, your range function would looks like this:
Download AS3 version of Tweener or have a look at TweenMax: http://www.greensock.com/tweenmax and just replace the Tweener code to TweenMax. Very easy to do.
from:
to:
Try it. Should be easier than you think ;) If you get stuck or have quesions, fire away!