00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 import amg.*;
00011
00012
00013 class amg.GalleryMenu extends MovieClip {
00014
00015
00016 private var MenuHeader:MovieClip;
00017 public var menuHeaderEvent:String;
00018 public var txtMenuHeader:TextField;
00019 private var _iHeaderWidth:Number = 0;
00020 private var _iMenuHeaderLineHeight:Number = 16;
00021 private var _iMenuHeaderLeftMargin:Number = 7;
00022 private var _iMenuHeaderRightMargin:Number = 7;
00023 public var _bMenuHover:Boolean = false;
00024 public var _bMenuOpen:Boolean = false;
00025
00026
00027 private var menuItem:MovieClip;
00028 private var MenuItemsBorder:MovieClip;
00029 private var _aMenuItems:Array;
00030 private var _iMenuItemDepth:Number = 10;
00031
00032
00033 public var _iCurrItemsWidth:Number = 0;
00034 private var _iMenuItemLineHeight:Number = 16
00035 private var _iMenuItemRightMargin:Number = 40;
00036 private var _iMenuItemLeftMargin:Number = 15;
00037
00038 private var _iMenuHeaderFillColor:Number = 0x666666;
00039 private var _iMenuHeaderHoverColor:Number = 0x000000;
00040 private var _iMenuHeaderTextColor:Number = 0xffffff;
00041 private var _iMenuItemFillColor:Number = 0x666666;
00042 private var _iMenuItemHoverColor:Number = 0x000000;
00043
00044 private var _oMouseListener:Object;
00045
00046
00047
00048
00049
00050
00051 public function GalleryMenu() {
00052
00053 this._aMenuItems = new Array();
00054 this.MenuHeader = this.createEmptyMovieClip("menuHeader",1);
00055
00056 this.MenuHeader.createEmptyMovieClip("MenuFill",1);
00057 this.MenuHeader.createEmptyMovieClip("HoverState",2);
00058 this.MenuItemsBorder = this.createEmptyMovieClip("MenuItemsBorder",2000);
00059 this.MenuItemsBorder._visible = false;
00060 this.MenuItemsBorder._y = _iMenuHeaderLineHeight;
00061
00062
00063 }
00064
00065 public function initMenu(menuTitle:String,menuEvent:String,p_tabIndex:Number){
00066 this.MenuHeader.tabIndex = p_tabIndex;
00067 this.MenuHeader.createTextField("txtMenuHeader", 3,_iMenuHeaderLeftMargin, -1, 20, _iMenuHeaderLineHeight);
00068 this.MenuHeader.txtMenuHeader.multiline = false;
00069 this.MenuHeader.txtMenuHeader.wordWrap = false;
00070 this.MenuHeader.txtMenuHeader.embedFonts = false;
00071 this.MenuHeader.txtMenuHeader.autoSize = "left";
00072 this.MenuHeader.txtMenuHeader.selectable = false;
00073 var menuHeaderFmt:TextFormat = new TextFormat();
00074 menuHeaderFmt.color = 0xFFFFFF;
00075
00076 menuHeaderFmt.font = "Arial";
00077 menuHeaderFmt.size = 11;
00078 this.MenuHeader.txtMenuHeader.text = menuTitle;
00079 this.MenuHeader.txtMenuHeader.setTextFormat(menuHeaderFmt);
00080 this._iHeaderWidth = _iMenuHeaderLeftMargin + this.MenuHeader.txtMenuHeader._width + _iMenuHeaderRightMargin;
00081 this.menuHeaderEvent = menuEvent;
00082
00083
00084 this.MenuHeader.MenuFill.beginFill(_iMenuHeaderFillColor);
00085 this.MenuHeader.MenuFill.moveTo(0,0)
00086 this.MenuHeader.MenuFill.lineTo(this._iHeaderWidth,0);
00087 this.MenuHeader.MenuFill.lineTo(this._iHeaderWidth,_iMenuHeaderLineHeight);
00088 this.MenuHeader.MenuFill.lineTo(0,_iMenuHeaderLineHeight);
00089 this.MenuHeader.MenuFill.lineTo(0,0);
00090 this.MenuHeader.MenuFill.endFill();
00091
00092 this.MenuHeader.HoverState.beginFill(_iMenuHeaderHoverColor);
00093 this.MenuHeader.HoverState.moveTo(0,0)
00094 this.MenuHeader.HoverState.lineTo(this._iHeaderWidth,0);
00095 this.MenuHeader.HoverState.lineTo(this._iHeaderWidth,_iMenuHeaderLineHeight);
00096 this.MenuHeader.HoverState.lineTo(0,_iMenuHeaderLineHeight);
00097 this.MenuHeader.HoverState.lineTo(0,0);
00098 this.MenuHeader.HoverState.endFill();
00099
00100 this.MenuHeader.HoverState._visible = false;
00101 this.MenuHeader.onRollOver = headerRollOver;
00102 this.MenuHeader.onRollOut = headerRollOut;
00103 this.MenuHeader.onPress = headerClick;
00104 this.MenuHeader.onRelease = headerRelease;
00105 this.MenuHeader.onReleaseOutside = headerRelease;
00106
00107
00108
00109 }
00110
00111 public function setHeaderTextColor(newColor:String){
00112 var menuHeaderFmt:TextFormat = new TextFormat();
00113 menuHeaderFmt.color = parseInt("0x"+newColor);
00114 this.MenuHeader.txtMenuHeader.setTextFormat(menuHeaderFmt);
00115 }
00116
00117 public function setHeaderBgColor(newColor:String,alpha:String){
00118 this.setTint(this.MenuHeader.MenuFill,newColor,alpha);
00119 }
00120
00121 public function setHeaderHoverColor(newColor:String,alpha:String){
00122 this.setTint(this.MenuHeader.HoverState,newColor,alpha);
00123 }
00124
00125 public function setItemsTextColor(newColor:String){
00126 var menuHeaderFmt:TextFormat = new TextFormat();
00127 menuHeaderFmt.color = parseInt("0x"+newColor);
00128 for(var i:Number=0;i<this._aMenuItems.length;i++){
00129 _aMenuItems[i].txtMenuItem.setTextFormat(menuHeaderFmt);
00130 this.setTint(_aMenuItems[i].menuCheck,newColor,"100");
00131 }
00132 }
00133 public function setItemsBgColor(newColor:String,alpha:String){
00134 for(var i:Number=0;i<this._aMenuItems.length;i++){
00135 this.setTint(_aMenuItems[i].MenuFill,newColor,alpha)
00136 }
00137 }
00138
00139 public function setItemsHoverColor(newColor:String,alpha:String){
00140 for(var i:Number=0;i<this._aMenuItems.length;i++){
00141 this.setTint(_aMenuItems[i].HoverState,newColor,alpha)
00142 }
00143 }
00144
00145
00146 public function setItemsBorderColor(newColor:String,alpha:String){
00147 this.setTint(this.MenuItemsBorder,newColor,alpha);
00148 }
00149
00150
00151 private function headerRollOver(Void):Void{
00152 this._parent._bMenuHover = true;
00153 eval(this+".HoverState")._visible = true;
00154 _parent._parent.dispatchEvent("menuHeaderRollover",this._parent);
00155 }
00156
00157 private function headerRollOut(Void):Void{
00158 this._parent._bMenuHover = false;
00159 if(!this._parent._bMenuOpen)
00160 eval(this+".HoverState")._visible = false;
00161 }
00162
00163 private function headerClick(Void):Void{
00164 _parent.dispatchEvent("menuHeaderClick",this._name);
00165
00166 }
00167 private function headerRelease(Void):Void{
00168
00169 }
00170
00171 private function itemRollOver(itemId:Number):Void{
00172 this._parent._bMenuHover = true;
00173 eval(this+".HoverState")._visible = true;
00174 }
00175
00176 private function itemRollOut(Void):Void{
00177 this._parent._bMenuHover = false;
00178 eval(this+".HoverState")._visible = false;
00179 }
00180
00181 private function itemClick(Void):Void{
00182
00183
00184 if(eval(this+".menuEvent") == "livePreview"){
00185 _root.extLivePreview(eval(this+".menuPrevNode"));
00186 }
00187 _parent.dispatchEvent("menuItemClick",eval(this+".menuEvent"));
00188
00189
00190 if(eval(this+".menuType") == "radio"){
00191 for(var i=0;i<_parent._aMenuItems.length;i++){
00192 _parent._aMenuItems[i].menuCheck._visible = false;
00193 }
00194 eval(this+".menuCheck")._visible = true;
00195 }
00196
00197 eval(this+".HoverState")._visible = false;
00198 }
00199
00200 public function setSelectedItem(itemEvent:String){
00201 for(var i=0;i<_aMenuItems.length;i++){
00202 if(_aMenuItems[i].menuEvent == itemEvent)
00203 _aMenuItems[i].menuCheck._visible = true;
00204 else
00205 _aMenuItems[i].menuCheck._visible = false;
00206 }
00207 }
00208
00209 public function unSelectAllItems(itemEvent:String){
00210 for(var i=0;i<_aMenuItems.length;i++){
00211 _aMenuItems[i].menuCheck._visible = false;
00212 }
00213 }
00214
00215
00216 public function addMenuItem(menuTitle:String,menuType:String,isSelected:Boolean,menuEvent:String,p_tabIndex:Number,prevNode:String){
00217 var menuItem:MovieClip = this.createEmptyMovieClip("menuItem"+this._aMenuItems.length,_iMenuItemDepth++);
00218 menuItem.tabIndex = p_tabIndex;
00219 menuItem._visible = false;
00220 menuItem.id = this._aMenuItems.length;
00221 menuItem.menuTitle = menuTitle;
00222 menuItem.menuType = menuType;
00223 menuItem.menuEvent = menuEvent;
00224 menuItem.menuPrevNode = prevNode;
00225 menuItem.isSelected = isSelected;
00226
00227 if(menuTitle == "Separator"){
00228 menuItem.createEmptyMovieClip("MenuFill",1);
00229 menuItem.attachMovie("MenuSeparator","menuSeparator",2,{_x:3,_y:(_iMenuItemLineHeight/2)-2,_width:this._iCurrItemsWidth-6});
00230
00231 menuItem._y = _iMenuItemLineHeight + (_iMenuItemLineHeight*this._aMenuItems.length);
00232
00233 menuItem.MenuFill.lineStyle(0, _iMenuItemFillColor, 100, true, "none", "round", "miter", 1);
00234 menuItem.MenuFill.beginFill(_iMenuItemFillColor);
00235 menuItem.MenuFill.moveTo(0,0);
00236 menuItem.MenuFill.lineTo(this._iCurrItemsWidth,0);
00237 menuItem.MenuFill.lineTo(this._iCurrItemsWidth,_iMenuItemLineHeight);
00238 menuItem.MenuFill.lineTo(0,_iMenuItemLineHeight);
00239 menuItem.MenuFill.lineTo(0,0);
00240 menuItem.MenuFill.endFill();
00241 menuItem.onPress = function () {
00242
00243 };
00244
00245 }
00246 else {
00247 menuItem.createEmptyMovieClip("MenuFill",1);
00248 menuItem.createEmptyMovieClip("HoverState",2);
00249
00250
00251 menuItem.attachMovie("MenuCheck","menuCheck",30,{_visible:isSelected});
00252 menuItem.HoverState._visible = false;
00253
00254 menuItem.createTextField("txtMenuItem", 3,_iMenuItemLeftMargin,0, 100, _iMenuItemLineHeight);
00255 menuItem.txtMenuItem.multiline = false;
00256 menuItem.txtMenuItem.wordWrap = false;
00257 menuItem.txtMenuItem.autoSize = "left";
00258 menuItem.txtMenuItem.embedFonts = false;
00259 menuItem.txtMenuItem.selectable = false;
00260 var menuHeaderFmt:TextFormat = new TextFormat();
00261 menuHeaderFmt.color = 0xFFFFFF;
00262 menuHeaderFmt.font = "Arial";
00263 menuHeaderFmt.size = 11;
00264 menuItem.txtMenuItem.text = menuTitle;
00265 menuItem.txtMenuItem.setTextFormat(menuHeaderFmt);
00266 this._iHeaderWidth = _iMenuItemLeftMargin + menuItem.txtMenuItem._width + _iMenuItemRightMargin;
00267 menuItem._y = _iMenuItemLineHeight + (_iMenuItemLineHeight*this._aMenuItems.length);
00268
00269 if(_iMenuItemLeftMargin + menuItem.txtMenuItem._width + _iMenuItemRightMargin > this._iCurrItemsWidth){
00270
00271 this._iCurrItemsWidth = _iMenuItemLeftMargin + menuItem.txtMenuItem._width + _iMenuItemRightMargin;
00272
00273 for(var i = 0;i<this._aMenuItems.length;i++){
00274
00275 if(this._aMenuItems[i].menuTitle == "Separator"){
00276 this._aMenuItems[i].menuSeparator._width = this._iCurrItemsWidth - 6;
00277 }
00278 else {
00279 this._aMenuItems[i].HoverState._width = this._iCurrItemsWidth;
00280 }
00281 this._aMenuItems[i].MenuFill._width = this._iCurrItemsWidth;
00282
00283 totalMenuHeight += this._iMenuItemLineHeight;
00284 }
00285 }
00286
00287
00288 menuItem.MenuFill.lineStyle(0, _iMenuItemFillColor, 100, true, "none", "round", "miter", 1);
00289 menuItem.MenuFill.beginFill(_iMenuItemFillColor);
00290 menuItem.MenuFill.moveTo(0,0);
00291 menuItem.MenuFill.lineTo(this._iCurrItemsWidth,0);
00292 menuItem.MenuFill.lineTo(this._iCurrItemsWidth,_iMenuItemLineHeight);
00293 menuItem.MenuFill.lineTo(0,_iMenuItemLineHeight);
00294 menuItem.MenuFill.lineTo(0,0);
00295 menuItem.MenuFill.endFill();
00296
00297 menuItem.HoverState.beginFill(_iMenuItemHoverColor);
00298 menuItem.HoverState.moveTo(0,0)
00299 menuItem.HoverState.lineTo(this._iCurrItemsWidth,0);
00300 menuItem.HoverState.lineTo(this._iCurrItemsWidth,_iMenuItemLineHeight);
00301 menuItem.HoverState.lineTo(0,_iMenuItemLineHeight);
00302 menuItem.HoverState.lineTo(0,0);
00303 menuItem.HoverState.endFill();
00304
00305 var totalMenuHeight:Number = (this._aMenuItems.length+1) * _iMenuItemLineHeight;
00306 this.MenuItemsBorder.clear();
00307 this.MenuItemsBorder.lineStyle(0, 0xffffff, 100, true, "none", "round", "miter", 1);
00308 this.MenuItemsBorder.moveTo(0,0);
00309 this.MenuItemsBorder.lineTo(this._iCurrItemsWidth,0);
00310 this.MenuItemsBorder.lineTo(this._iCurrItemsWidth,totalMenuHeight);
00311 this.MenuItemsBorder.lineTo(0,totalMenuHeight);
00312 this.MenuItemsBorder.lineTo(0,0);
00313
00314 menuItem.onRollOver = itemRollOver;
00315 menuItem.onRollOut = itemRollOut;
00316 menuItem.onPress = itemClick;
00317 }
00318
00319 this._aMenuItems.push(menuItem);
00320
00321 }
00322
00323 public function removeMenuItem(itemEvent:String){
00324 var tempArray:Array = new Array();
00325 for(var i:Number=0;i<this._aMenuItems.length;i++){
00326 if(this._aMenuItems[i].menuEvent != itemEvent){
00327 var tempItem:Object = new Object;
00328 tempItem.menuTitle = this._aMenuItems[i].menuTitle;
00329 tempItem.menuType = this._aMenuItems[i].menuType;
00330 tempItem.isSelected = this._aMenuItems[i].isSelected;
00331 tempItem.menuEvent = this._aMenuItems[i].menuEvent;
00332 tempArray.push(tempItem);
00333 }
00334 this._aMenuItems[i].removeMovieClip();
00335 }
00336 this._aMenuItems = new Array();
00337 for(var i:Number=0;i<tempArray.length;i++){
00338 this.addMenuItem(tempArray[i].menuTitle,tempArray[i].menuType,tempArray[i].isSelected,tempArray[i].menuEvent);
00339 }
00340 }
00341
00342
00343 public function removeAllMenuItems(itemEvent:String){
00344 for(var i:Number=0;i<this._aMenuItems.length;i++){
00345 this._aMenuItems[i].removeMovieClip();
00346 }
00347 }
00348
00349 public function rollAsClick(){
00350 this.showMenus(true);
00351 }
00352
00353 private function dispatchEvent(eventName:String,eventValue:Object){
00354 switch(eventName) {
00355 case "menuHeaderClick" :
00356 if(this._bMenuOpen){
00357 this.showMenus(false);
00358 this._parent.dispatchEvent("menuClose");
00359 }
00360 else{
00361 this.showMenus(true);
00362 this._parent.dispatchEvent("menuOpen");
00363 }
00364 break;
00365 case "menuItemClick" :
00366 this.showMenus(false);
00367 this._parent.dispatchEvent(eventValue);
00368 this._parent.dispatchEvent("menuClose");
00369 break;
00370 case "menuItemReleaseOutside" :
00371 this.showMenus(false);
00372 this._parent.dispatchEvent("menuOpen");
00373 break;
00374 case "closeMenu":
00375 if(!_bMenuHover)
00376 this.showMenus(false);
00377 break;
00378
00379
00380 }
00381 }
00382
00383 private function showMenus(toOpen:Boolean){
00384
00385 this._bMenuOpen = toOpen;
00386 for(var i=0;i<this._aMenuItems.length;i++){
00387 _aMenuItems[i]._visible = toOpen;
00388 }
00389 this.MenuItemsBorder._visible = toOpen;
00390 if(!toOpen)
00391 this.MenuHeader.HoverState._visible = false;
00392 }
00393
00394
00395
00396
00397
00398
00399 function setTint(clip:MovieClip,hexval:String,alpha:String):Void {
00400 hexval = "0x" + hexval;
00401 var colorVal = parseInt(hexval);
00402 var alphaVal = parseInt(alpha);
00403 var color:Color = new Color(clip);
00404 var oColorTransform:Object = new Object();
00405 oColorTransform.ra = oColorTransform.ga = oColorTransform.ba = 0;
00406 oColorTransform.rb = (colorVal >> 16) & 0xFF;
00407 oColorTransform.gb = (colorVal >> 8) & 0xFF;
00408 oColorTransform.bb = colorVal & 0xFF;
00409 oColorTransform.ab = ((alphaVal/100)*255)-255;
00410 color.setTransform(oColorTransform);
00411 }
00412
00413
00414 }