Sep 01

This is a a Simple Fish Eye Menu (or Dock Menu). The logic is simple and you may further customize it as your own menu. It included both Flash and Silverlight version with complete source codes.

You can find similar resources from ComponentOne as well.

Comparison

Flash implementation: 1 hour
Silverlight implementation: 1 hour
Code variation in the source code:

  • Attach Mouse Event: MouseEvent.MOUSE_MOVE [AS3] vs MouseEventHandler [C#]

Source codes

Flash

Silverlight

Attach Mouse Event: MouseEvent.MOUSE_MOVE [AS3] vs MouseEventHandler [C#]

After you have attached a mouse event handler, you may retrieve the mouse position from the local perspective (e.localX) or from the stage perspective (e.stageX). However, if you would get the position with respect to other movieclip, then you may have to use the method globalToLocal to calculate the values.

// AS3
// make sure the display object is added to the stage
// before calling the stage variable
stage.addEventListener(MouseEvent.MOUSE_MOVE, on_mouse_move);

// mouse event handler
private function on_mouse_move(e : MouseEvent):void{
    // get x
    var localX:Number = e.localX;
    var stageX:Number = e.stageX;
}

Let’s look into case in C#. You must always specific the perspective as a parameter in the GetPosition method. Please also note that if you would like to get the root element, you can retrieve it by reference to Applicatoin.Current.RootVisual.

// C#
this.MouseMove +=new MouseEventHandler(MouseMove);

// mouse event handler
void  MouseMove(object sender, MouseEventArgs e)
{
    // get x with the perspective of this
    double localX = e.GetPosition(this).X;
    double stageX = e.GetPosition(Application.Current.RootVisual).X;
}