Shuffle Grid Demo

Drag & Drop the images to shuffle them around…

A friend of mine, Dale Sattler over at No Ponies recently posted a grid sorting class. He said it was based on my old dynamic stacking menu; but that was pure modesty as his script is based on a 2D grid and much more sophisticated.

Anyway – it inspired me to create a grid sorting / shuffling algorithm of my own. It behaves differently to Dales but I think it works pretty well.

The basic logic of the algorithm works by determining how far a dragged item travels along the grid (rows and columns) and then shuffling the surrounding items in the opposite direction by these values, therefore creating space for the dragged item to slot into when released.

It currently only works for grids which are fully populated, but adding more flexibility for incomplete grids will only be a matter of adding a few conditions – functionality which I’ll add when I get a moment.

You can extend the ShuffleGridItem class to add the functionality you need. In the demo I’ve made a simple image class which grabs a photo from Flickr.

Creating a ShuffleGrid is very simple, and can be done like so:

var grid:ShuffleGrid = new ShuffleGrid(4,7,40,40,1);

for (var i : int = 0; i < grid.numCells; i++)
{
	grid.addItem (new ShuffleGridItem());
}

addChild (grid);

The constructor takes the following arguments:

new ShuffleGrid(rows, cols, cellWidth, cellHeight, spacing);

Feel free to download the class and a simple demo and have a play around. I can imagine many uses for it, so hopefully it will come in handy.

Download: Shuffle Grid Class & Demo
Posted on 04 Mar 2009
58 Comments
9 Trackbacks

Meta

AS3 Shuffle Grid Class was posted on March 4th 2009 in the category Code / Actionscript 3.0, Code, Flash, Lab, Open Source and tagged; , , , , , , .

You can Leave a comment.

Twitter <follow>

February 7th 2012 - 5:37pm

RT @_leonardsouza_: 37signals to stop developing for IE8 http://t.co/wL6dtZSg

Discussion

63 Responses to AS3 Shuffle Grid Class

1 2 3 ... 6

Leave a Reply

Pingbacks / Trackbacks

  1. 2 years ago Bookmarks for March 5th from 15:03 to 15:06 « what i say // jon burger

    [...] AS3 Drag and Drop Shuffle Grid Menu Interface – [...]

  2. 2 years ago My First Game | PUBLIC SERVICE

    [...] soulwire’s Shufle Grid Class we present you PUZZLE NO [...]

  3. 2 years ago AntScript » 一个不错的效果收藏

    [...] 原文地址:http://blog.soulwire.co.uk/flash/flash-interfaces/as3-drag-drop-shuffle-grid-menu/#more-311 [...]

  4. 2 years ago Adobe — наш верный друг » AS3 Shuffle Grid Class — блог о air, flash, flex и других технологиях Adobe

    [...] делится своим видением области применения данной штуки. Можете поддержать [...]

  5. 2 years ago [Actionscript 3] Menu tipo iPhone con icone spostabili

    [...] ricerca.. ecco dove l’avevo visto noponies AS3 Drag Sort Grid Experiment e qui ce n’

  6. 1 year ago AnthemGDA » Blog Archive » 15 Detailed Expert Tutorials for ActionScript 3

    [...] 4. AS3 Shuffle Grid Class [...]

  1. noponies 2 years ago

    Nice work here Justin, certainly much more elegant than my hack job!

    Reply to this comment

  2. Ben 2 years ago

    Yummy.
    Nice work indeed.

    Reply to this comment

  3. P.J. Onori 2 years ago

    I love what you’ve done here. I would really like to find a way to integrate this with my Layout Organizers project.

    Great work man.

    Reply to this comment

  4. fenixkim 2 years ago

    wow, is very interesting.

    Reply to this comment

  5. Emil 2 years ago

    Awesome work. How about support for scrolling ?

    Reply to this comment

  6. Pedro 2 years ago

    Thanks for sharing mate, very clever and useful.
    What’s the license/copyright of this code, can I adapt it to my needs?

    cheers

    Reply to this comment

  7. dai 2 years ago

    this is great, thanks for the inspiration and source

    Reply to this comment

  8. Soulwire 2 years ago

    @P.J Definitely man! Perhaps we could work out a more flexible way to shuffle elements, which can be applied to all your layouts, similar to the [rows][cols] dictionary method I’m using in the grid. That way all the layouts could be rearranged an keep their basic ‘shape’. Love the idea!

    @Emil How do you mean scrolling?

    @Pedro Please feel free to adapt to your needs. As with most content on this site, I’ve released it under the Creative Commons 3 license, so go ahead and mix it up – just credit the author (me) where appropriate

    Reply to this comment

  9. Alex Littlejohn 2 years ago

    fully awesome.

    Reply to this comment

  10. Ahad Bokhari 2 years ago

    Dood, i met up with a client in morning who wanted something like this (if i can tweak it a little further)..I also tweeted about this post…Came out to be a perfect

    featureBlend: AS 3.0 Shuffle Grid Class (Justin does it again, WOOT,WOOT!!!) http://tinyurl.com/bd8us8

    Reply to this comment

  11. Jan Willem 2 years ago

    You did it again Justin, very very nice!

    Reply to this comment

  12. Loris 2 years ago

    Great project! And what can I do if I want to order elements with different width and height? I think that can be a good increase….

    Reply to this comment

1 2 3 ... 5