Hello guys,
I'm struggling with my rotating menu and
have prepared a short test case - please see
http://pastebin.com/m40cf66ec and I'll also
paste the code at the bottom of this mail.
In my rotating menu I'd like to rotate
button like objects in an ellipse.
1) I'd like to stop rotating if the mouse
is clicked down at any place at the stage.
Can I detect it from inside of the
handleEnterFrame() or do I have to
introduce a variable and add a listener
for MOUSE_DOWN and _UP events?
2) Any advice please on how to get
the z-sorting right? Earlier in AS2
I just called swapDepths(-y),
but in AS3 I can't use just any value
for a depth.
3) The buttons which are rotated can
be clicked and are scaled down then.
This is not shown in my test case...
But the issue I have is: the handleEnterFrame()
constantly sets scaleX and scaleY
for every button - i.e. the clicking
on them kind of stops working.
Does anybody have an ingenious
line of code how fix it here?
Any advices, nice tricks very welcome!
Thank you
Alex
package {
import flash.display.*;
import flash.events.*;
import flash.filters.*;
public class RotMenu extends Sprite {
public static const W:uint = 120;
public static const H:uint = 80;
public static const R:uint = 32;
public static const BLUR:BlurFilter = new BlurFilter(2, 2,
1);
private static const SHADOW:DropShadowFilter =
new DropShadowFilter(8, 80, 0x000000, 0.4, 32, 32,
1, 1, false, false, false);
private static var A:Number;
private static var B:Number;
private static const GR:Number = Math.PI / 180;
private var start:Number = 0;
private var delta:Number = 0;
public function RotMenu(total:uint) {
delta = Math.min(60, 360 / total);
for (var i:uint = 0; i < total; i++) {
var rect:Sprite = new Sprite();
// do not show the rect before its coordinates
// have been set by handleEnterFrame()
rect.visible = false;
rect.graphics.lineStyle(0, 0x00FF00);
rect.graphics.beginFill(0xFFFF00);
rect.graphics.drawRoundRect(-W/2, -H/2, W, H,
R);
rect.graphics.endFill();
rect.tabIndex = i;
addChild(rect);
}
addEventListener(Event.ADDED_TO_STAGE, handleAdded);
addEventListener(Event.ENTER_FRAME, handleEnterFrame);
}
private function handleAdded(event:Event):void {
A = (stage.stageWidth / 2 - W) / 2;
B = (stage.stageHeight / 2 - H) / 2;
}
private function handleEnterFrame(event:Event):void {
// the starting angle - for the 1st rect
start += mouseX / 100;
for (var i:int = numChildren - 1; i >= 0; i--) {
var rect:Sprite = getChildAt(i) as Sprite;
var angle:Number = start + delta *
rect.tabIndex;
// scale the rect from (0.70-0.30) to
(0.70+0.30)
rect.scaleX = rect.scaleY = 0.7 + 0.3 *
Math.sin(angle * GR);
rect.x = A * Math.cos(angle * GR);
rect.y = -B * Math.sin(angle * GR);
rect.filters = (rect.y > 16 ? [BLUR, SHADOW] :
[SHADOW]);
// add B to prevent negative depths
//rect.swapDepths(B - rect.y); <--- this was
AS2 trick
rect.visible = true;
}
}
}
}
And then in the .fla file (550x400px):
stop();
var rot:RotMenu = new RotMenu(6);
rot.x = stage.stageWidth / 2;
rot.y = stage.stageHeight / 2;
addChild(rot);
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders