Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-13-2009, 08:57 PM   #1
Subhaus design
Registered User
 
Join Date: Oct 2009
Posts: 3
Default Resorting Array

Hi,

I'm sure that someone probably asked about this problem, but after 2 days of googling I haven't find anything similar.

I'm making some vertical menu where button (actually mc) on click should tween to the end of menu.

I've try to splice clicked item, and after that to push it back to the same array so it will go to it's end. After that, I've plan to change y position of all items through for loop and using Tweener.

here's my code:

ActionScript Code:
import caurina.transitions.*; var mits:Array = new Array("about", "biography", "work"); var mitems:Array = new Array(); for(var i:int = 0; i<mits.length; i++) {     var mitem:menuItm = new menuItm();     mitem.id = i;     mitem.itm_txt.text = mits[i];     mitem.itm_txt.wordWrap = false;     mitem.itm_txt.autoSize = TextFieldAutoSize.LEFT;     mitem.x = 10;     mitem.y = 10+i*40;     mitem.name = "mitem"+i;     menus.addChild(mitem);     mitem.buttonMode = true;     mitem.mouseChildren = false;     mitems.push(mitem);     mitem.addEventListener(MouseEvent.CLICK, moveItems); } function moveItems(e:MouseEvent):void {     var spliced:Array = mitems.splice(e.target.id, 1);     mitems.push(spliced);     for(var a:int = 0; a<mitems.length; a++) {         var ipsilon:Number = 10+(a*40);         Tweener.addTween(mitems[a], {y:ipsilon, time:1});         trace(mitems[a].id);     } }

this code works for only few clicks (3 I think). The output look like this:

Quote:
0
2
undefined

---------------------

2
undefined
undefined

---------------------

2
undefined
## [Tweener] Error: The property 'y' doesn't seem to be a normal object property of [object menuItm] or a registered special property.
undefined
I've try also with eather older Tweener class and TweenLite. Using them I'm not getting error, but the script is acting the same.

What am I doing wrong?

ps. sorry for my bad english. Hope you've understand.
Subhaus design is offline   Reply With Quote
Old 10-13-2009, 10:02 PM   #2
kingundkong
kingundkong
 
kingundkong's Avatar
 
Join Date: Jul 2009
Posts: 320
Default

i think you need to do this: (explenation in the code)
ActionScript Code:
import caurina.transitions.*; var mits:Array = new Array("about", "biography", "work"); var mitems:Array = new Array(); for(var i:int = 0; i<mits.length; i++) {     var mitem:menuItm = new menuItm();     mitem.id = i;     mitem.itm_txt.text = mits[i];     mitem.itm_txt.wordWrap = false;     mitem.itm_txt.autoSize = TextFieldAutoSize.LEFT;     mitem.x = 10;     mitem.y = 10+i*40;     mitem.name = "mitem"+i;     this.addChild(mitem);     mitem.buttonMode = true;     mitem.mouseChildren = false;     mitems.push(mitem);     mitem.addEventListener(MouseEvent.CLICK, moveItems); } function moveItems(e:MouseEvent):void {     var spliced:Array = mitems.splice(e.target.id, 1);     mitems.push(spliced[0]); // push not the whole array but just the menuItm to the mitems array     for(var a:int = 0; a<mitems.length; a++) {         var mc:menuItm=mitems[a];         mc.id=a; // reassing the id variable, cause you getting a new order after mixing         var ipsilon:Number = 10+(a*40);         Tweener.addTween(mitems[a], {y:ipsilon, time:1});         trace(mitems[a].id);     } }
__________________
kingundkong is offline   Reply With Quote
Old 10-13-2009, 10:04 PM   #3
kingundkong
kingundkong
 
kingundkong's Avatar
 
Join Date: Jul 2009
Posts: 320
Default

sorry , i changed this line:
ActionScript Code:
this.addChild(mitem);
just for testing. just change it again to
ActionScript Code:
menus.addChild(mitem);
__________________
kingundkong is offline   Reply With Quote
Old 10-13-2009, 10:11 PM   #4
Subhaus design
Registered User
 
Join Date: Oct 2009
Posts: 3
Default

wow, this was fast. Thanks man. Your really king! (and kong ofcourse), and you've just made my day!
Subhaus design is offline   Reply With Quote
Old 10-13-2009, 10:21 PM   #5
kingundkong
kingundkong
 
kingundkong's Avatar
 
Join Date: Jul 2009
Posts: 320
Default

you are welcome !
__________________
kingundkong is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:45 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.