PDA

View Full Version : Access image size in TileList cell



Akuma99
November 29th, 2009, 04:02 PM
Hi all,

Done a search of the internet world and just can't nut this one out. I am using the default TileList component in AS3/CS4, where a user can upload their images and it is displayed in the TileList by using the URL of the upload as the source parameter.

The final piece of the puzzle is knowing the dimensions of the image that was uploaded, but bugger me if I can find how to access each image that is displayed in each cell of the tilelist. I can of course get the dimensions of the cell itself (which of course is always the same for each one), but I want the content of the scaled image within the cell ... any ideas?

Cheers
Adam

shaji
November 30th, 2009, 07:03 AM
Adam, I couldn't find any built in method or functions to find height and width. Idea what comes to my mind is to load the item as loader and find the height and width property.

If mouseEvent is added to tilelist we can find the URL of the image clicked using

evt.currentTarget.selectedItem.source

load that image using loader and check for height and width. Probably there is a better way till some else directs in that way.

dail
November 30th, 2009, 09:55 AM
Something like this;



private function itemClickHandler(event:ListEvent):void {
var myTileList:TileList = event.target as TileList;
var renderer:ImageCell = myTileList.itemToCellRenderer(event.item) as ImageCell;
for (var i:Number = 0; i < renderer.numChildren; i++) {
if(renderer.getChildAt(i) is UILoader) trace(UILoader(renderer.getChildAt(i)).content.wid th, i)
}
}


Usually the content is at depth 1, but you can never be sure if that is always so. Hence the iteration over the children on the ImageCell.