Heyo, so Dr. Amateur here with a question.
I’m trying to make a cool navigation system but have been stuck on the same problem for the last few hours. Maybe one of you AS super geniuses can tell me what I’m doing wrong.
Basically, when you click on a number in the first row, the bar slides over in a sexy easing fashion over to the right and re-adjusts the positions of the others. This is working perfectly. Then, when you click on one of the buttons on the second row, I need the row to resize (bigger, vertically) and the 1st one to be reduced to make space.
This seems like it should be toddlers play to make happen, but, whenever I change the height of an object it moves away from its original position. How can I prevent this? What am I doing wrong?
I feel like I’m just missing something small because I have no idea what I’m doing with AS3. Anyone got any tips?
Here is codes:
import fl.transitions.Tween;
import fl.transitions.easing.*;
var p_tot:Number = 40;
var p_spc:Number = 20;
var pnum:RegExp = /[a-z_]+/;
var p_runs:Number = 0;
var p_runz:Number = 0;
var p_curr:Number = 0;
var p_last:Number = 0;
function arger(method:Function, args:Array):Function {
return function(event:Event):void {
method.apply(null, [event].concat(args));
}
}
function p_scoot(e:Event):void {
var thiser:Number = Number(e.currentTarget.name.replace(pnum, ''));
p_runs++;
var v:Number = (10-Math.floor(p_runs*.7) > 2)?10-Math.floor(p_runs*.7):2;
var fm:Number = (p_tot>20)?(thiser>20?p_tot:20):p_tot;
if (p_last > thiser) fm = p_last;
if (p_last > 0 && p_last < thiser) {
for (var x=(p_last+1); x<=thiser; x++) {
getChildByName("p_butt_"+x).x -= v;
}
if (getChildByName("p_butt_"+(p_last+1)).x <= 0) {
e.currentTarget.removeEventListener(Event.ENTER_FRAME, p_scoot);
p_last = thiser;
}
} else {
for (var i=(thiser+1); i<=fm; i++) {
getChildByName("p_butt_"+i).x += v;
}
if (getChildByName("p_butt_"+(thiser+1)).x >= 80) {
e.currentTarget.removeEventListener(Event.ENTER_FRAME, p_scoot);
p_last = thiser;
}
}
}
function p_size(e:Event):void {
var thiser:Number = Number(e.currentTarget.name.replace(pnum, ''));
var fm:Number = (p_tot>20)?(thiser>20?p_tot:20):p_tot;
p_runz++;
for (var i=21; i<=fm; i++) {
var o:Object = getChildByName("p_butt_"+i)
var s:Tween = new Tween(o.getChildByName("p_l_"+i), "height", Strong.easeOut, 0, 95, 4, true);
}
e.currentTarget.removeEventListener(Event.ENTER_FRAME, p_size);
}
function p_go(e:MouseEvent, p_n:Number):void {
p_curr = p_n;
p_runs = 0;
e.currentTarget.getChildByName("p_h_"+p_n).alpha = 1;
if (e.currentTarget.getChildByName("p_l_"+p_n).height < 60) {
e.currentTarget.addEventListener(Event.ENTER_FRAME, p_size);
}
if (p_last > 0) {
trace(p_last);
var o:Object = getChildByName("p_butt_"+p_last);
o.getChildByName("p_h_"+p_last).alpha = 0;
}
e.currentTarget.addEventListener(Event.ENTER_FRAME, p_scoot);
}
function p_mo(e:MouseEvent, p_n:Number, dir:String):void {
if (p_n != p_curr) e.currentTarget.getChildByName("p_h_"+p_n).alpha = (dir == 'in')?1:0;
}
function p_butt(p_x:Number, p_y:Number, p_n:Number, p_r:int) {
var dad:Sprite = new Sprite();
var f:TextFormat = new TextFormat();
var t:TextField = new TextField();
var l:Sprite = new Sprite();
var b:Sprite = new Sprite();
var m:Sprite = new Sprite();
f.font = "Futura";
f.color = 0x464324;
f.size = 10;
t.defaultTextFormat = f;
t.selectable = false;
t.text = String(p_n+100).substr(1, 2);
t.x = p_x;
t.y = p_y+(p_r == 1?18:80);
t.width = 20;
t.height = 20;
l.graphics.lineStyle(1, 0x000000, 100, true, LineScaleMode.NONE);
l.graphics.moveTo (p_x, p_y);
l.graphics.lineTo (p_x, p_y+(p_r == 1?32:95));
l.name = "p_l_"+p_n;
b.graphics.beginFill (0x464324, 60);
b.graphics.moveTo (p_x+3, p_y+(p_r == 1?5:45));
b.graphics.lineTo (p_x+13, p_y+(p_r == 1?0:40));
b.graphics.lineTo (p_x+13, p_y+(p_r == 1?20:82));
b.graphics.lineTo (p_x+3, p_y+(p_r == 1?20:82));
b.graphics.endFill();
b.alpha = 0;
b.name = "p_h_"+p_n;
dad.graphics.beginFill (0x464324, 0);
dad.graphics.drawRect(p_x, p_y, 20, (p_r == 1?40:100));
dad.addChild(b);
dad.addChild(l);
dad.addChild(t);
dad.buttonMode = true;
dad.addEventListener(MouseEvent.CLICK, arger(p_go, [p_n]));
dad.addEventListener(MouseEvent.ROLL_OVER, arger(p_mo, [p_n, 'in']));
dad.addEventListener(MouseEvent.ROLL_OUT, arger(p_mo, [p_n, 'out']));
dad.name = "p_butt_"+p_n;
addChild(dad);
}
for (var i=1; i<=p_tot; i++) {
if (i <= 20) p_butt(p_spc*i, 100, i, 0);
else p_butt(p_spc*(i-20), 200, i, 1);
}
Thanks.