MenuItem class
package
{
import flash.events.MouseEvent;
import flash.text.TextField;
import biz.Flashscript.filters.DropShadow;
/*
* The MenuItem extends the Component class, which is for
* objects with parent behaviour.
*/
public class MenuItem extends Component
{
private static var myShadow:DropShadow;
public function MenuItem (myNum:Array,myText:String,_url:String)
{
super (myNum,myText,_url);
/*
* We add a textfield to the Sprite.
*/
var tf:TextField = new TextField ;
tf.width = width;
tf.height = height;
tf.text = myText;
tf.mouseEnabled = false;
tf.autoSize = "center";
addChild (tf);
/*
* We set buttonmode and add mouse events.
*/
buttonMode = true;
addEventListener (MouseEvent.MOUSE_OVER,overHandler);
addEventListener (MouseEvent.MOUSE_OUT,outHandler);
addEventListener (MouseEvent.CLICK,clickHandler);
}
/*
* On rollover we create a dropshadow, which we eliminate on rollout.
*/
private function overHandler (event:MouseEvent):void
{
myShadow = new DropShadow(this);
deleteItems ();
}
private function outHandler (event:MouseEvent):void
{
myShadow = new DropShadow(this,0,0,0xFFFFCC);
}
private function clickHandler (event:MouseEvent):void
{
if (numItems != null)
{
/*
* On pressing the MenuItem we create the children and add them to our Displaylist
* using the "addItems" function.
*/
for (var i:int = 0; i < numItems.length; i++)
{
var mySub:Composite = new SubMenuItem(numItems[i].headLine,numItems[i]._url);
mySub.y = (mySub.height + 5) * i;
mySub.x = 150;
addChild (mySub);
addItems (mySub);
}
}
else
{
/*
* This function is triggered when there are no children.
*/
showItem ();
}
}
}
}