Button variable problem

Hi,

Please could somebody point me in the right direction with this ? Its an image gallery and I want to trace the id of the photo. I can do this fine when the photo is selected, but I also want to be able to click a button and have it trace which photo is selected. When I try it always says 9 which is the last one, no matter which photo I pick.

Thanks very much

function released()
{
 for(var  i=0;i<numOfItems;i++)
 {
  var t:MovieClip =  home["item"+i];
  t.xPos = t._x;
  t.yPos = t._y;
  t.theScale =  t._xscale;
  if(t != this._parent)
  {
   var tw:Tween = new  Tween(t,"_xscale",Strong.easeOut,t._xscale,0,1,true);
  }
  else
  {
   var  tw:Tween = new  Tween(t,"_xscale",Strong.easeOut,t._xscale,100,1,true);
   theText.htmlText =  t.content;
     t.empty.attachMovie("katestext","katestext2",this.getNextHighestDepth());
     trace (t) <<<this works  fine
   t.empty.katestext2.modbtn.onRelease=function(){
                trace(t) <<<this always returns photo 9
 }
  
   }
 
  }
 }