Salut, j'ai donné la réponse de Jascha le plus un parce qu'il sert le but, mais je vais juste vous promener dans le code ci-dessous afin que vous puissiez comprendre comment ce genre de chose est atteint. Il a également un certain nombre de contrôles/configurations supplémentaires
//these are your button instances
var originalOrder:Array = [tom, dick, harry, jane];
//this is a reference to the currently selected item
var selectedItem:MovieClip = tom;
//these are the co-ordinates of where the first item should be placed
var offsetX:Number = 100;
var offsetY:Number = 100;
//this is how much padding you want between items
var padding:Number = 8;
addEventListener(MouseEvent.CLICK, mouseClickHandler);
private function mouseClickHandler(e:Event):void
{
var index:int = originalOrder.indexOf(e.target);
//if the thing have clicked is in our array of buttons it is valid, we
//could have clicked something else interactive
if(index > -1)
{
//update the reference to the newly selected item
selectedItem = originalOrder[index];
//move the items about
calculatePlacement();
}
}
private function calculatePlacement():void
{
//we want to start with our x-position being the current offset
//plus the selectedItem's width plus the padding
var cumlativeWidth:Number = offsetX + selectedItem.width + padding;
var item:MovieClip;
//loop over all the items in our list in the order they are specified
for(var i:int = 0; i<originalOrder.length; i++)
{
//assign item to the currently looped item
item = originalOrder[i];
//if the item we are looking at is the selected item, place it at the
//offset position
if(item == selectedItem)
{
item.x = offsetX;
item.y = offsetY;
//We could tween using Tweener/TweenLite
//TweenLite.to(item, 1, {x:offsetX, y:offsetY});
}
//otherwise put it at our x-position, then add on its width + padding
//to the cumulative x-position.
else
{
item.x = cumlativeWidth;
item.y = offsetY;
//We could tween using Tweener/TweenLite
//TweenLite.to(item, 1, {x:offsetX, y:offsetY});
cumlativeWidth += item.width + padding;
}
}
}
Cette question ressemble terriblement à "écrire mon code pour moi". Il ne semble pas que vous ayez fait un travail par vous-même. – davr
Si vous êtes sur Flex, vous pouvez facilement le faire avec un HBox - il suffit de changer les indices enfants. En flash, je ne suis pas au courant des contrôles API qui font cela. Vous devrez l'écrire par vos propres moyens. – Amarghosh