
Код:
import flash.display.BitmapData;
import flash.geom.Rectangle;
import mx.transitions.Tween;
import mx.transitions.easing.*;
//
function rct(mc:MovieClip,w:Number,h:Number,a:Array):MovieClip {
var _mc:MovieClip = mc.createEmptyMovieClip("_mc"+mc.getNextHighestDepth(),mc.getNextHighestDepth());
if(a[0] instanceof BitmapData){
_mc.beginBitmapFill(a[0]);
} else {
_mc.beginFill(a[0],a[1]);
}
_mc.moveTo(-w/2,-h/2);
_mc.lineTo(w/2,-h/2);
_mc.lineTo(w/2,h/2);
_mc.lineTo(-w/2,h/2);
_mc.lineTo(-w/2,-h/2);
_mc.endFill();
return _mc;
}
var _bmp:BitmapData = new BitmapData(8,8,false,0xffffff);
_bmp.fillRect(new Rectangle(0,0,4,4),0);
_bmp.fillRect(new Rectangle(4,4,4,4),0);
var _map:MovieClip = rct(this,400,400,[_bmp]);
_map._x = Stage.width/2;
_map._y = Stage.height/2;
var _obj:MovieClip = rct(_map,20,20,[0xff00ff,100]);
_obj._x = Math.floor(-_map._width/2+10+(_map._width-20)*Math.random());
_obj._x = _obj._x-(2+_obj._x%4);
_obj._y = Math.floor(-_map._height/2+10+(_map._height-20)*Math.random());
_obj._y = _obj._y-(2+_obj._y%4);
var _tw:Tween = new Tween({i:0},"i",Elastic.easeOut,0,100,5,true);
_tw.stop();
_tw.addListener(this);
_tw.addListener(_map);
_tw.addListener(_obj);
function onMotionFinished():Void {
_tw.yoyo();
}
_map.onMotionChanged = function():Void {
this._xscale = this._yscale = 100-_tw.obj.i/2;
}
_obj.onMotionChanged = function():Void {
this._xscale = this._yscale = 100+_tw.obj.i;
}
_map.onPress = function():Void {
_tw.start();
}
_map.onRelease = function():Void {
_tw.stop();
}
Пример