Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Adobe AIR Development

Reply
Developer
DT655
Posts: 71
Registered: ‎04-27-2011
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();
addChild(_thumbnailsContainer);

for(i2=0;i2<_files[1].length;i2++)
{ //run through files array
	fileURL = filePath + _files[1][i2];
	//trace(fileURL + "\n\n");
	thumbnail = new Thumbnail(fileURL,width,height);
	thumbnail.addEventListener(MouseEvent.CLICK, onClick);
	_thumbnailsContainer.addChild(thumbnail);			
	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);
	_loader.load(request);
	
	//setTimeout(function():void { _loader.load(request); }, 100);
	addChild(_loader);
}
		
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.

 

Please use plain text.
Developer
Developer
CMY
Posts: 1,115
Registered: ‎02-10-2009
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;
   } 
}

 

 

Please use plain text.