Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.Loader;
- import flash.display.Sprite;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- import flash.events.Event;
- import flash.net.URLRequest;
- class Tile extends Sprite
- {
- public function new(url:String)
- {
- super();
- var loader = new Loader();
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
- loader.load(new URLRequest(url));
- }
- function onLoadComplete(event:Event):Void
- {
- var loader:Loader = event.currentTarget.loader;
- var content:Bitmap = cast(loader.content, Bitmap);
- var source:BitmapData = content.bitmapData;
- var sourceRect = new Rectangle(0,0,50,50);
- var destPoint = new Point(0,0);
- var bmd = new BitmapData(50,50);
- bmd.copyPixels(source, sourceRect, destPoint);
- var bmp = new Bitmap(bmd);
- addChild(bmp);
- }
- }
- class Main extends Sprite
- {
- public function new()
- {
- super();
- var tile = new Tile("image.jpg");
- tile.x = 320;
- tile.y = 0;
- }
- public static function main()
- {
- flash.Lib.current.addChild(new Main());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment