# Dynamic Image Index Swapping

**URL:** <https://forum.kirupa.com/t/dynamic-image-index-swapping/263229>\
**Category:** flash\
**Created:** [June 13, 2008, 3:25pm UTC](https://forum.kirupa.com/t/dynamic-image-index-swapping/263229 "2008-06-13T15:25:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbdvd7](https://avatars.discourse-cdn.com/v4/letter/d/f07891/32.png) [@dbdvd7](https://forum.kirupa.com/u/dbdvd7)\
**Post date:** [June 13, 2008, 3:25pm UTC](https://forum.kirupa.com/t/dynamic-image-index-swapping/263229/1 "2008-06-13T15:25:35Z")

</div>

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:
[LEFT][COLOR=#0000FF]for[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000] **var** [/COLOR] i:uint = [COLOR=#000080]0[/COLOR]; i &lt; xmlData.[COLOR=#000080]logos[/COLOR].[COLOR=#000080]pic[/COLOR].[COLOR=#0000FF]length[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]; i++[COLOR=#000000])[/COLOR]
[COLOR=#000000]{[/COLOR]
    thumbLoader = [COLOR=#000000] **new** [/COLOR] Loader[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
    thumbLoader.[COLOR=#0000FF]load[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000] **new** [/COLOR] URLRequest[COLOR=#000000]([/COLOR] xmlData.[COLOR=#000080]logos[/COLOR].[COLOR=#000080]pic[/COLOR].[COLOR=#000080]thumb[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];
            
    thumbClip = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]MovieClip[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
    thumbClip.[COLOR=#000080]logoValue[/COLOR] = logoValue++;
    thumbClip.[COLOR=#000080]addChild[/COLOR][COLOR=#000000]([/COLOR]thumbLoader[COLOR=#000000])[/COLOR];
    thumbClip.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE_OVER[/COLOR], overThumb[COLOR=#000000])[/COLOR];
    thumbClip.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE_OUT[/COLOR], outThumb[COLOR=#000000])[/COLOR];
    thumbClip.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]CLICK[/COLOR], showBigImage[COLOR=#000000])[/COLOR];
    
    [COLOR=#808080]*//TweenLite.to(thumbClip, 2, {alpha:.5});*[/COLOR]
    thumbClip.[COLOR=#000080]x[/COLOR] = [COLOR=#000080]95[/COLOR] * i + padding;
    thumbClip.[COLOR=#000080]scaleX[/COLOR] = thumbClip.[COLOR=#000080]scaleY[/COLOR] = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]random[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]* .[COLOR=#000080]4[/COLOR] + .[COLOR=#000080]9[/COLOR];
    thumbClip.[COLOR=#000080]rotation[/COLOR] -= [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]random[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] * [COLOR=#000080]20[/COLOR] + [COLOR=#000080]350[/COLOR] ;
    
    logoHolder.[COLOR=#000080]addChild[/COLOR][COLOR=#000000]([/COLOR]thumbClip[COLOR=#000000])[/COLOR];
    
                                           
[COLOR=#000000]}[/COLOR]

```

[/LEFT]

and my listener:

```
ActionScript Code:
[LEFT][COLOR=#000000] **function** [/COLOR] overThumb[COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#0000FF]void[/COLOR]

```

[COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]trace[/COLOR]COLOR=#000000[/COLOR];  
TweenLite.[COLOR=#000080]to[/COLOR][COLOR=#000000]([/COLOR]event.[COLOR=#0000FF]target[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000000]{[/COLOR]scaleX: [COLOR=#000080]1[/COLOR].[COLOR=#000080]3[/COLOR], scaleY:[COLOR=#000080]1[/COLOR].[COLOR=#000080]3[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];  
event.[COLOR=#0000FF]target[/COLOR].[COLOR=#000080]parent[/COLOR].[COLOR=#000080]swapChildrenAt[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000080]0[/COLOR], event.[COLOR=#0000FF]target[/COLOR].[COLOR=#000080]parent[/COLOR].[COLOR=#000080]getChildIndex[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000])[/COLOR];

[COLOR=#000000]}[/COLOR]  
[/LEFT]

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![dbdvd7](https://avatars.discourse-cdn.com/v4/letter/d/f07891/32.png) [@dbdvd7](https://forum.kirupa.com/u/dbdvd7)\
**Post date:** [June 14, 2008, 10:20pm UTC](https://forum.kirupa.com/t/dynamic-image-index-swapping/263229/2 "2008-06-14T22:20:49Z")

</div>

got it figured out:

event.currentTarget.parent.swapChildrenAt(event.currentTarget.parent.getChildIndex(event.currentTarget), event.currentTarget.parent.numChildren - 1);

---

<div class="post-metadata">

**Author:** ![dbdvd7](https://avatars.discourse-cdn.com/v4/letter/d/f07891/32.png) [@dbdvd7](https://forum.kirupa.com/u/dbdvd7)\
**Post date:** [June 14, 2008, 10:21pm UTC](https://forum.kirupa.com/t/dynamic-image-index-swapping/263229/3 "2008-06-14T22:21:19Z")

</div>

opps forgot the code block

```auto

event.currentTarget.parent.swapChildrenAt(event.currentTarget.parent.getChildIndex(event.currentTarget), event.currentTarget.parent.numChildren - 1);

```
