jan_flanders

Untitled

Dec 17th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package;
  2. import flash.display.Bitmap;
  3. import flash.display.BitmapData;
  4. import flash.display.Loader;
  5. import flash.display.Sprite;
  6. import flash.geom.Point;
  7. import flash.geom.Rectangle;
  8. import flash.events.Event;
  9. import flash.net.URLRequest;
  10.  
  11. class Tile extends Sprite
  12. {
  13.     public function new(url:String)
  14.     {
  15.         super();
  16.         var loader = new Loader();
  17.         loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
  18.         loader.load(new URLRequest(url));
  19.     }
  20.     function onLoadComplete(event:Event):Void
  21.     {
  22.         var loader:Loader = event.currentTarget.loader;
  23.         var content:Bitmap = cast(loader.content, Bitmap);
  24.         var source:BitmapData = content.bitmapData;
  25.        
  26.         var sourceRect = new Rectangle(0,0,50,50);
  27.         var destPoint = new Point(0,0);
  28.         var bmd = new BitmapData(50,50);
  29.         bmd.copyPixels(source, sourceRect, destPoint);
  30.         var bmp = new Bitmap(bmd);
  31.         addChild(bmp);
  32.     }
  33. }
  34.  
  35. class Main extends Sprite
  36. {
  37.    
  38.     public function new()
  39.     {
  40.         super();
  41.         var tile = new Tile("image.jpg");
  42.     tile.x = 320;
  43.     tile.y = 0;
  44.     }
  45.     public static function main()
  46.     {
  47.         flash.Lib.current.addChild(new Main());
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment