Welcome, Guest. Please login or register.
Did you miss your activation email?
05/21/12, 04:16
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash 8 (Moderators: Jorge Solis, ..:: Mazhar Hasan ::.., Andresss)
| | |-+  Re-shuffling menu (clicked item slides to top...)
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Re-shuffling menu (clicked item slides to top...)  (Read 3068 times)
3stripe
Seasoned Programmer
***
Posts: 153


View Profile WWW
« on: 03/29/06, 05:54 »

Hi folks  Smiley

Inspired by some of the examples at http://laco.wz.cz/tween/, I'm trying to build a reshuffling menu... Whichever item you click slides to the top, and the previously selected item to the bottom, with the rest of the items in the list moving up one to fill in the gaps.

I've coded a quick example of what would happen when you clicked nav item 2, but I now need to turn this into a re-usable function.

Should I be making better use of an array to keep track of what position each item is at?

Or has someone done this type of thing before?

// intialise
selectedButton "nav1";
transitionLength 0.3;
transitionType "easeOutQuad";
xposition 548;
// click functions
0;
nav2.onRelease = function() {
   
// fade out top button
   
fadeOut = eval(selectedButton);
   
fadeOut.alphaTo(0transitionLength"easeOutQuad"0moveClickedToBottom);
   
// slide clicked button to top
   
this.slideTo(xposition268);
   
// move other buttons up
   
nav3.slideTo(xposition281);
   
nav4.slideTo(xposition296);
   
nav5.slideTo(xposition,311);
   
nav6.slideTo(xposition326);
   
// move click button to bottom;
   
function moveClickedToBottom() {
      
nav1.slideTo(xposition341transitionLengthtransitionTypetransitionLength);
      
nav1.alphaTo(100transitionLengthtransitionTypetransitionLength);
      
ssp.loadAlbum("yachts");
   }
   
delete this.onRelease;
};

Cheers 3stripe
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #1 on: 03/29/06, 06:07 »

The idea should be something like this when pressing any button:

- If I'm below clicked item, should move one position up (one position is the heigth of an item plus an offset)
- If I'm over clicked item nothing except if I'm the last selected
- If I'm the clicked item, should let know all of the rest of the items and move to the top position
- If I'm the last selected item (say myFlag is set to true) should move to the botton position

Begin with a top and botton fixed position (and of course a fixed number of items) When you can manage a fixed quantity, then you can try with a variable one

Jorge
Logged

3stripe
Seasoned Programmer
***
Posts: 153


View Profile WWW
« Reply #2 on: 03/29/06, 06:08 »

Thanks for the logic Jorge, very helpful as usual  Grin
Logged
3stripe
Seasoned Programmer
***
Posts: 153


View Profile WWW
« Reply #3 on: 03/29/06, 11:30 »

I'm getting there - it works perfectly on the first click.... then it starts going wrong:

// ATTACH BUTTONS
this.attachMovie("nav_a""nav0"1, {_x:548_y:268});
this.attachMovie("nav_b""nav1"2, {_x:548_y:281});
this.attachMovie("nav_c, "nav2", 3, {_x:548, _y:296});
this.attachMovie("
nav_d", "nav3", 4, {_x:548, _y:311});
this.attachMovie("
nav_e", "nav4", 5, {_x:548, _y:326});
this.attachMovie("
nav_f", "nav5", 6, {_x:548, _y:341});
//
// STARTUP VARIABLES
selectedButton = "
0";
transitionLength = 0.3;
transitionType = "
easeOutQuad";
xposition = 548;
yoffset = 268;
//
// BUILD ARRAY
var portfolioNav = new Array("
_level0.portfolio.nav0", "_level0.portfolio.nav1", "_level0.portfolio.nav2", "_level0.portfolio.nav3", "_level0.portfolio.nav4", "_level0.portfolio.nav5");
//
// CLICK FUNCTIONS
for (var i:Number = 0; i<portfolioNav.length; i++) {
	
var c = eval(portfolioNav[i]);
	
c.onRelease = function() {
	
	
clicked = this._name;
	
	
var clicked:String = new String(this._name);
	
	
var clickedPosition:String = new String();
	
	
_root.clickedPosition = clicked.substr(3, 1);
	
	
trace("
you clicked on the item at position "+_root.clickedPosition);
	
	
// SHUFFLE MENU
	
	
shuffleNav();
	
};
}
//
// SHUFFLE FUNCTION
k = 0;
function shuffleNav() {
	
for (var i:Number = 0; i<portfolioNav.length; i++) {
	
	
// find out which item is being checked
	
	
var itemToCheck:String = "
_level0.portfolio.nav"+k;
	
	
// find out position of this item in the portfolioNav array
	
	
var myPosition:Number = portfolioNav.getIndex(itemToCheck);
	
	
var clickedPositionNumber:Number = _root.clickedPosition;
	
	
// MOVE THE CLICKED ITEM;
	
	
var c = eval(clicked);
	
	
c.slideTo(xposition, 268, transitionLength, transitionType);
	
	
// MOVE THE TOP ITEM;
	
	
var d = eval(portfolioNav[selectedButton]);
	
	
d.slideTo(xposition, 341, transitionLength, transitionType);
	
	
// IF I'M BELOW THE CLICKED ITEM
	
	
if (myPosition>_root.clickedPosition) {
	
	
	
// move up one position in the list
	
	
	
trace("
NOTE"+itemToCheck+" is underneath the item you just clicked ("+clicked+")");
	
	
	
var e = eval(portfolioNav[i]);
	
	
	
e.slideTo(xposition, e._y-15, transitionLength, transitionType);
	
	
}
	
	
k++;
	
}
	
// NOW MENU HAS RE-ORDERED, REORDER ARRAY TO MATCH!
	
reorderMenu();
}
// REORDER ARRAY FUNCTION
function reorderMenu() {
	
// REORDER THE ARRAY TO MATCH ACTUAL MOVEMENTS
	
// Send first item to end
	
portfolioNav.push(portfolioNav[0]);
	
// Delete first item as it now exists at end
	
portfolioNav.shift();
	
// Send clicked item to start of array as it is now at the top
	
portfolioNav.unshift("
_level0.portfolio."+clicked);
	
// Delete clicked item from previous position in the array
	
portfolioNav.splice(_root.clickedPosition, 1);
	
trace(portfolioNav);
	
// FINALLY SET CLICKED BUTTON!
	
selectedButton = _root.clickedPosition;
	
trace("
new selectedButton ="+selectedButton);
}
//
//
// FIND POSITION IN ARRAY
Array.prototype.getIndex = function(data) {
	
for (i=0; i<this.length; ++i) {
	
	
if (this[i] == data) {
	
	
	
return i;
	
	
}
	
}
	
return "
error";
};
Logged
nothingGrinder
Mods
Systems Administrator
*****
Posts: 823


Automatic websites with social media distribution


View Profile WWW
« Reply #4 on: 03/30/06, 09:14 »

couldnt download that extension you are using, from the link that you gave
Logged

3stripe
Seasoned Programmer
***
Posts: 153


View Profile WWW
« Reply #5 on: 03/30/06, 11:15 »

Hey cinegod, did you try http://laco.wz.cz/tween/files/MovieclipTween120.mxp

Still working on the code, I think the array is re-ordering fine, but something still going very wrong with multiple clicks
Logged
nothingGrinder
Mods
Systems Administrator
*****
Posts: 823


Automatic websites with social media distribution


View Profile WWW
« Reply #6 on: 03/30/06, 17:49 »

James,
yeah, i tired that but it just gives me all the source code written out in the browser window.

so i did a test and replaced the slide with a tween and i got some really crazy stuff too.
Logged

Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #7 on: 03/31/06, 04:17 »

Ok, here's a working example:

http://flash-db.com/Tutorials/temp/myMenu.html

I have writed very quickly, so could be better. Here's the class managing this:

import mx.transitions.Tween
import mx
.transitions.easing.*
import mx.utils.Delegate

class myMenu extends MovieClip{
	
var 
h:Number//Menu heigth
	
var 
sel:Number //selected menu
	
var 
oldSel:Number //last selected menu
	
var 
cant:Number //quantity of menues
	
var 
square:MovieClip //This is for designers, they need some visual feedback pf menu area
	

	
function 
myMenu(){
	
	
square._visible false     
	
}
	
function 
setMenu(items:Array){
	
	
cant items.length
	
	

	
	
var 
t:MovieClip
	
	
//Attach items based on the array passed
	
	
for(var 
i=0i<canti++){
	
	
	

	
	
	
attachMovie("item""item"+ii, {_y:(i>0)?t._y+t._height 0nr:i})
	
	
	

	
	
	
t.menu_txt.text items[i//set items text
	
	
	
if(
h==undefinedt._height
	
	
	
t.onPress = function(){
	
	
	
	
if(
_parent.sel==this.nr) return //I'm yet selected
	
	
	
	
_parent.setSel(this.nr)
	
	
	
	
_parent.move(this._y)
	
	
	
	
var 
myColor = new Color(this.back).setRGB(0x999999)
	
	
	
}
	
	
	
t.onRollOver = function(){
	
	
	
	
var 
myColor= new Color(this.back).setRGB(0x999999)
	
	
	
}
	
	
	
t.onRollOut = function(){
	
	
	
	
if(
this.nr!=_parent.sel) var myColor= new Color(this.back).setRGB(0xCCCCCC)
	
	
	
}
	
	
}
	
}
	
//old and new selected
	
function 
setSel(selected:Number){
	
	
oldSel sel
	
	
sel selected
	
}
	
//Move on baby !
	
function 
move(py:Number){
	
	

	
	
for(var 
i=0i<canti++){
	
	
	
if(
this["item"+i].nr==oldSel) {
	
	
	
	
new 
Tween(this["item"+i], "_y"Regular.easeIn,this["item"+i]._y, (cant-2)*h1true)
	
	
	
	
var 
myColor= new Color(this["item"+i].back).setRGB(0xCCCCCC)
	
	
	
} else if(
this["item"+i].nr==sel) new Tween(this["item"+i], "_y"Regular.easeInthis["item"+i]._y, -h1true)
	
	
	
else if(
py<this["item"+i]._y) new Tween(this["item"+i], "_y"Regular.easeInthis["item"+i]._ythis["item"+i]._y-h1true)
	
	
}
	
	
	

	
}
}

Here are the files

I don't use Lacko prototypes since the Tween class was included in Flash core as version 7. Also there's no need of further array manipulation, just implement the items movement logic, that could be guessed by the context. The first time the item move one position up of the starting menu position, then just change with the others.
Could be improved of course. If some of you want to take it, add a few things (i.e the action to perform in the onPress) and write some little article to upload to Flash-db would be great!

Jorge
« Last Edit: 03/31/06, 04:19 by Jorge Solis » Logged

3stripe
Seasoned Programmer
***
Posts: 153


View Profile WWW
« Reply #8 on: 03/31/06, 08:31 »

WOW! AMAZING!  Grin

That's made my day, thanks Jorge!

I will do my best to write a nice tutorial for you as a way of saying thanks.
Logged
3stripe
Seasoned Programmer
***
Posts: 153


View Profile WWW
« Reply #9 on: 03/31/06, 08:46 »

Sorry, one question, how do I include this in my movie clip? Using #include?

Ok think I got it!

Haha so funny that I'm meant to be a 'seasoned' programmer now...
« Last Edit: 03/31/06, 09:30 by james greig » Logged
3stripe
Seasoned Programmer
***
Posts: 153


View Profile WWW
« Reply #10 on: 06/26/06, 04:13 »

Hi Jorge,

I'm having a few problems with this menu... it gets stuck sometimes and stops working (after clicking it a lot)

It's live on the Portfolio section at http://tinyurl.com/ogq57 but I can't figure out what is making it get stuck....  Roll Eyes

import mx.transitions.Tween

import mx
.transitions.easing.*

import mx.utils.Delegate



class myMenu extends MovieClip{

	
var 
h:Number//Menu height

	
var 
sel:Number //selected menu

	
var 
oldSel:Number //last selected menu

	
var 
cant:Number //quantity of menues

	
var 
square:MovieClip //This is for designers, they need some visual feedback of menu area
	
var 
menuStatus "stopped";
	
// Make marker square invisible
	
function 
myMenu(){
	
square._visible false     

	
}

	
function 
setMenu(items:Array){
	
var 
thisclass this;
	
trace("thisclass = "+thisclass);

	
	
cant items.length
	
	


	
	
var 
t:MovieClip

	
	
//Attach items based on the array passed

	
	
for(var 
i=0i<canti++){
	
	
	


	
	
	
attachMovie("item""item"+ii, {_y:(i>0)?t._y+t._height 0nr:i})
	
	
	


	
	
	
t.menu_txt.text items[i//set items text

	
	
	
if(
h==undefinedt._height

	
	
	
t.onPress = function(){

	
	
	
	
if(
_parent.sel==this.nr) return //I'm already selected
	
	
	
	
if (
thisclass.menuStatus == "stopped") {

	
	
	
	
_parent.setSel(this.nr)

	
	
	
	
_parent.move(this._y)

	
	
	
	
var 
myColor = new Color(this).setRGB(0x226777)
	
	
	
	
thisclass.menuStatus "loading";
	
	
	
	
trace(thisclass.menuStatus);
	
	
	
	
}
	
	
	
}

	
	
	
t.onRollOver = function(){

	
	
	
	
var 
myColor= new Color(this).setRGB(0x226777)

	
	
	
}

	
	
	
t.onRollOut = function(){

	
	
	
	
if(
this.nr!=_parent.sel) var myColor= new Color(this).setRGB(0x000000)

	
	
	
}

	
	
}
	
	
setSel(0);
	
	
move(0);
	
}

	
//old and new selected

	
function 
setSel(selected:Number){

	
	
oldSel sel

	
	
sel selected

	
}
	
//Move on baby !

	
function 
move(py:Number){
	
var 
thisclass this;

	
	
for(var 
i=0i<canti++){

	
	
	
if(
this["item"+i].nr==oldSel) {

	
	
	
	
var 
tween1 = new Tween(this["item"+i], "_y"Regular.easeIn,this["item"+i]._y, (cant-2)*h0.3true)
	
	
	
	
var 
myColor= new Color(this["item"+i]).setRGB(0x000000)
	
	
	
	
tween1.onMotionFinished = function() {
	
	
	
	
	
trace('tween1 finished');
	
	
	
	
thisclass.menuStatus "stopped";
	
	
	
	
};

	
	
	
} else if(
this["item"+i].nr==sel) {
	
	
	
	
var 
tween2 = new Tween(this["item"+i], "_y"Regular.easeInthis["item"+i]._y, -h0.3true);
	
	
	
	
tween2.onMotionFinished = function() {
	
	
	
	
	
trace('tween2 finished');
	
	
	
	
	
//menuStatus = "stopped";
	
	
	
	
};
	
	
	
}

	
	
	
else if(
py<this["item"+i]._y) { 
	
	
	
	
var 
tween3 = new Tween(this["item"+i], "_y"Regular.easeInthis["item"+i]._ythis["item"+i]._y-h0.3true);
	
	
	
	
tween3.onMotionFinished = function() {
	
	
	
	
	
trace('tween3 finished');
	
	
	
	
	
//menuStatus = "stopped";
	
	
	
	
};
	
	
	
}

	
	
}

	
}
}
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #11 on: 06/26/06, 04:43 »

Usually interfaces get stuck when people click as a crazy. As a general rule, disable interaction until transition finish is a good rule. It's relative easy disabling prototypes:

Button.prototype.enabled = false or MovieClip.prototype.enabled = false

Then reenabling when transition finish. When using Tween, onMotionfinished is the rigth place to re-enable.

Jorge
Logged

Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
anything