PDA

View Full Version : Dynamic Image Index Swapping



dbdvd7
June 13th, 2008, 11:25 AM
Im dynamically loading external images via an XML file and creating 4 scrolling image galleries on one screen. When the user scrolls over any image, the scales are tweened and everything works...except one thing. I need the individual images to come to swap indexes to 0. I've tried swapChildren, swapChildrenAt, setChildIndex, etc.. but i've come to find out that when tracing: event.target.parent.getChildIndex(event.target); I get an index number of 0 for every image, therefor, nothing can be swapped to the top. What am I missing here?.. Heres a code excerpt:

ActionScript Code:

for(var i:uint = 0; i < xmlData.logos.pic.length(); i++)
{
thumbLoader = new Loader();
thumbLoader.load(new URLRequest( xmlData.logos.pic.thumb));

thumbClip = new MovieClip();
thumbClip.logoValue = logoValue++;
thumbClip.addChild(thumbLoader);
thumbClip.addEventListener(MouseEvent.MOUSE_OVER, overThumb);
thumbClip.addEventListener(MouseEvent.MOUSE_OUT, outThumb);
thumbClip.addEventListener(MouseEvent.CLICK, showBigImage);

[I]//TweenLite.to(thumbClip, 2, {alpha:.5});
thumbClip.x = 95 * i + padding;
thumbClip.scaleX = thumbClip.scaleY = Math.random()* .4 + .9;
thumbClip.rotation -= Math.random() * 20 + 350 ;

logoHolder.addChild(thumbClip);


}




and my listener:

ActionScript Code:

function overThumb(event:MouseEvent):void
{
trace(event.target.parent.getChildIndex(event.targ et));
TweenLite.to(event.target, 1, {scaleX: 1.3, scaleY:1.3});
event.target.parent.swapChildrenAt(0, event.target.parent.getChildIndex(event.target));

}




Thanks in advance...

dbdvd7
June 14th, 2008, 06:20 PM
got it figured out:

event.currentTarget.parent.swapChildrenAt(event.cu rrentTarget.parent.getChildIndex(event.currentTarg et), event.currentTarget.parent.numChildren - 1);

dbdvd7
June 14th, 2008, 06:21 PM
opps forgot the code block



event.currentTarget.parent.swapChildrenAt(event.cu rrentTarget.parent.getChildIndex(event.currentTarg et), event.currentTarget.parent.numChildren - 1);