flash 图片割断成两张动态效果
代码如下 |
复制代码 |
package {
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Rectangle;
public class Main extends Sprite {
private var loader:Loader;
public function Main():void {
loader=new Loader ;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadCompleteHandler);
loader.load(new URLRequest("mm.gif"));
}
private function onLoadCompleteHandler(_evt:Event ):void {
var _bitmap:Bitmap=_evt.target.content as Bitmap;
var _bmd:BitmapData=_bitmap.bitmapData;
for (var _p:uint =0; _p<5; _p++) {
var p_bmd:BitmapData=new BitmapData(_bmd.width,_bmd.height*.2);
p_bmd.copyPixels(_bmd,new Rectangle(0,_p*_bmd.height *.2,_bmd.width ,_bmd.height *.2),new Point());
var _sprite:Sprite=new Sprite ;
_sprite.addChild(new Bitmap(p_bmd));
_sprite.y=_p*_bmd.height*.2;
_sprite.name=_p%2?"-":"+";
addChild(_sprite).addEventListener(Event.ENTER_FRAME,onEnterFrameHandler);
}
}
private function onEnterFrameHandler(_evt:Event ):void {
var _sprite:Sprite =_evt.target as Sprite;
_sprite.name=="-"?_sprite.x-=3:_sprite.x+=3;
(_sprite.x<-_sprite.width||_sprite.x>stage.stageWidth)&&_sprite.removeEventListener(Event.ENTER_FRAME,onEnterFrameHandler);
}
}
}
|
http://www.zzzyk.com/down/split.rar 实例下载地址
补充:flash教程,动画技术