package com.flashden
{
import flash.display.MovieClip;
import flash.text.*;
import flash.events.MouseEvent;
import flash.events.*;
import flash.net.URLRequest;
import flash.display.Loader;
public class MenuItem extends MovieClip
{
private var scope;
public var closedX; :Number
public static const OPEN_MENU = "openMenu";
public function MenuItem(scope)
{
// set scope to talk back to -------------------------------//
this.scope = scope;
// disable all items not to be clickable -------------------//
txt_label.mouseEnabled = false;
menuItemShine.mouseEnabled = false;
menuItemArrow.mouseEnabled = false;
// make background clip the item to be clicked (button) ----//
menuItemBG.buttonMode = true;
// add click event listener to the header background -------//
menuItemBG.addEventListener(MouseEvent.CLICK, clickHandler);
}
private function clickHandler (e:MouseEvent)
{
scope.openMenuItem(this);
}
public function loadContent (contentURL:String)
{
var loader:Loader = new Loader();
configureListeners(loader.contentLoaderInfo);
var request:URLRequest = new URLRequest(contentURL);
loader.load(request);
// place x position of content at the bottom of the header so the top is not cut off ----//
loader.x = 30;
// we add the content at level 1, because the background clip is at level 0 ----//
addChildAt(loader, 1);
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
dispatcher.addEventListener(Event.INIT, initHandler);
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(Event.OPEN, openHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
dispatcher.addEventListener(Event.UNLOAD, unLoadHandler);
}
private function completeHandler(event:Event):void {
//trace("completeHandler: " + event);
// remove loader animation ----------------//
removeChild(getChildByName("mc_preloader"));
}
private function httpStatusHandler(event:HTTPStatusEvent):void {
// trace("httpStatusHandler: " + event);
}
private function initHandler(event:Event):void {
//trace("initHandler: " + event);
}
private function ioErrorHandler(event:IOErrorEvent):void {
//trace("ioErrorHandler: " + event);
}
private function openHandler(event:Event):void {
//trace("openHandler: " + event);
}
private function progressHandler(event:ProgressEvent):void {
//trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
}
private function unLoadHandler(event:Event):void {
//trace("unLoadHandler: " + event);
}
}
}