0
votes

I'm building a Tile Viewer in Adobe AIR and so far I have implemented the Drag and Drop function that allows the user to load PNG and JPG files.

The function returns a ':File' format, but how can i gram the ':Bitmap' data and place the image in an existing movieclip while looping and make that one tile image repeat in x and y so a preview of a tilemap will shown ?

my thought was to simply add instances of that one file, but i dont know the exact code for that. ( create a Loader, pass the File format to that, and get the BitmapData and place it in place by defining position x and y and also defining width and height. also i want to make instances, to the code doesnt load the image 10 x 10 times )

i would be glad for all helpfull answers.

Edit:

example theory:

( without correct syntax )

image = new ImageFromDropBox(); // bitmap or whatever

for( x = 0; x < 10; x++) {
    for( y = 0; y < 10; y++) {
        image.x = tilesize * x;
        image.y = tileSize * y;
        image.width = tileSize;
        image.height = tileSize;
        stage.addChild( image ); // so each of the 100 places images should be just instances of the ONE LOADED IMAGE
    }
}
1
Did you ever find a solution for this?BadFeelingAboutThis
yes i did, but there was some premission problems, so if i was draging an image into that app, the image could not been overwritten withother programms until the app is closed. i did the app in c# so i dont get much deeper intp thisAce

1 Answers

0
votes

When working with the File class, you can use the fileInstance.url parameter to load said file in a loader:

var loader:Loader = new Loader();
var urlReq:URLRequest = new URLRequest(file.url);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
loader.load(urlReq);

function loaded(e:Event):void {
    var bmp:Bitmap = loader.content as Bitmap

    //scale it down and create a scaled down bitmap data for more efficient memory usage
    bmp.width = tileSize;
    bmp.height = tileSize;

    var bData:BitmapData = new BitmapData(tileSize,tileSize); //your new bitmap data
    bData.draw(bmp); //capture the scaled down version of the bitmap

    //if you don't need the original anymore, dispose of it
    bmp.bitmapData.dispose();     

    var image:Bitmap;

    for( var x:int = 0; x < 10; x++) {
        for( var y:int = 0; y < 10; y++) {
            image = new Bitmap(bmp.bData);
            image.x = tilesize * x;
            image.y = tileSize * y;
            image.width = tileSize;
            image.height = tileSize;
            stage.addChild( image );
       }
   }
}