Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Posts: 71
Registered: ‎04-27-2011
My Device: Bold 9700 and Playbook 64
My Carrier: Rogers

find loaders width in class from main class

I have a thumbnail class that loads thumbnails of images... pretty self explanatory.


I call it from my main class and pass to the thumbnail class the width OR height I want them to be.... if the width is 100 pixels, then the height is based on the proper scale ratio so the proportions are correct.... this all works fine.


after having added the thumbnail class to the container, I would like to place the next thumbnail say 20 pixels or whatever away from the previous one... because the width of each of the thumbs is different, I need to find out the width of the last item added to add 20 pixels to it..


some code:


my main class calls the thumbnail class:

_thumbnailsContainer = new Sprite();

{ //run through files array
	fileURL = filePath + _files[1][i2];
	//trace(fileURL + "\n\n");
	thumbnail = new Thumbnail(fileURL,width,height);
	thumbnail.addEventListener(MouseEvent.CLICK, onClick);
	thumbnail.x = thumbnailX;
	thumbnail.y = thumbnailY;

------ Thumbnail class -----------

public function Thumbnail(url:String, defaultWidth:Number, defaultHeight:Number)
	//_mainAssetUrl = mainUrl;
	_height = defaultHeight;
	_loader = new Loader();
	var request:URLRequest = new URLRequest(url);
	_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, goToDefaultState);
	//setTimeout(function():void { _loader.load(request); }, 100);
public function goToDefaultState(event:Event):void
	var ratio:Number;
	ratio = _loader.width / _loader.height;
	_loader.height = _height;
	_loader.width = _height * ratio;
	//I NEED TO GET _loader.width to the main class for each child


 I''m unsure if thats clear or not.


Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: find loaders width in class from main class

Not really sure if this is exactly what you are talking about, but what I would do is add a listener to see when the thumbnail is added to the stage then you can use the parent to get access to the previous thumbnail and adjust its location. Something like this:



//Thumbnail class
public function adjustLocation(event:Event):void {
   var thumb:Thumbnail = e.object as Thumbnail;
   var thumbContainer:ThumbnailContainer = thumb.parent;
   var myIndex = thumbContainer.getChildIndex(thumb);
   if( myIndex > 0 ){
      var thumb2:Thumbnail = Thumbnail(thumbContainer.getChildAt(myIndex-1));
      thumb.x = thumb2.x + thumb2.width + 20;