I've got a movie with some buttons in the middle of the screen. I've got a tween on the buttons to make them grow/shrink on rollOver/rollOut, when a button is clicked, I've got a frame animation that moves the buttons to the top of the screen and shrinks them. This all works fine.
When the buttons grow, they need to appear on top of all the other buttons. Since there's no more swapDepths, I'm using setChildIndex to move the rolled over button to the top. Now, when I click one of the buttons (after rolling over it), any of the buttons I've rolled over aren't affected by the frame animation.
Here's the code, and I attached an fla file...any ideas??
Code:
import fl.transitions.*;
import fl.transitions.easing.*;
for (var i:int=1; i<=2; i++) {
this["btn"+i].addEventListener(MouseEvent.ROLL_OUT, mouseListener,false,0,true);
this["btn"+i].addEventListener(MouseEvent.ROLL_OVER, mouseListener,false,0,true);
this["btn"+i].addEventListener(MouseEvent.CLICK, mouseListener,false,0,true);
this["btn"+i].useHandCursor=true;
this["btn"+i].buttonMode=true;
}
var tw:Tween;
function mouseListener( event:MouseEvent ):void {
switch ( event.type ) {
case MouseEvent.ROLL_OVER :
tw = new Tween(event.target,"scaleX",Strong.easeOut,event.target.scaleX,1.5,.50,true);
tw = new Tween(event.target,"scaleY",Strong.easeOut,event.target.scaleY,1.5,.50,true);
var mc:MovieClip;
mc = event.target.parent as MovieClip;
mc.setChildIndex(mc.getChildByName((event.target as MovieClip).name), (mc.numChildren - 1));
break;
case MouseEvent.ROLL_OUT :
tw = new Tween(event.target,"scaleX",Strong.easeOut,event.target.scaleX,1.0,.50,true);
tw = new Tween(event.target,"scaleY",Strong.easeOut,event.target.scaleY,1.0,.50,true);
break;
case MouseEvent.CLICK :
gotoAndPlay("slideUp");
break;
}
}
stop();
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
You can just call addChild() again on the button to move it to the top. No need to for setChildIndex
I didn't use addChild to get the buttons on the screen, I just put them on the stage. Does that matter? In the fla I attached you can see that I'm still using the timeline way too much for AS3. I'm getting comfortable with the AS3 coding conventions, but still haven't made the breakthrough to complete OOP coding with one frame structure and external .as files.
Thanks!
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
Yeah I didn't want to nit-pick on all the extra work you're doing. Maybe if I have time later today I can show you a faster cleaner way to handle collections. (note to other FK users: if you hang out in the coffee lounge, you'll get better support from us CL'ers)
One of the many nice things about as3 is that they've blurred the line between author-time instances and run-time instances. It's all run-time after the compiler so you're free to manipulate stage children just as you would if you had created them through code.
Thanks, that would be fabulous. No rush on this, the client isn't even expecting to see anything until sometime next week, I'm working on all the other parts and it's just the depth swapping that's causing the issue, so I can just comment that out...
And yes, not only does hanging out in the CL help with getting your posts answered, but it's a great place to escape flash issues for a little while and get to know the community...and this is one of the best forum communities I've ever seen...
Thanks again!
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
Wow I gotta admit, it's been long enough since I worked in the IDE that I forgot how to deal with its stupid little quirks. It's actually duplicating your buttons every time it loops or something. I think the answer may be to move the core logic to a document class but I just don't have time today to dick with it.
lol...yeah, ain't it grand? No biggie, if you get a chance, that would be great. I'm debating dropping back and punting, either doing the motion with tweens (maybe switching to TweenLite or another class) or swapping over to as2.
Thanks!
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
Yeah I know it has to do with the multiple instances that actually exist for each key frame and when the play head loops back to one, things get run again. This is why I don't use timeline's anymore