home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / mx / controls / FlexNativeMenu.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  25.7 KB  |  847 lines

  1. package mx.controls
  2. {
  3.    import flash.display.InteractiveObject;
  4.    import flash.display.NativeMenu;
  5.    import flash.display.NativeMenuItem;
  6.    import flash.display.Stage;
  7.    import flash.events.Event;
  8.    import flash.events.EventDispatcher;
  9.    import flash.events.TimerEvent;
  10.    import flash.ui.Keyboard;
  11.    import flash.utils.Timer;
  12.    import flash.xml.XMLNode;
  13.    import mx.collections.ArrayCollection;
  14.    import mx.collections.ICollectionView;
  15.    import mx.collections.XMLListCollection;
  16.    import mx.collections.errors.ItemPendingError;
  17.    import mx.controls.menuClasses.IMenuDataDescriptor;
  18.    import mx.controls.treeClasses.DefaultDataDescriptor;
  19.    import mx.core.Application;
  20.    import mx.core.EventPriority;
  21.    import mx.core.UIComponentGlobals;
  22.    import mx.core.mx_internal;
  23.    import mx.events.CollectionEvent;
  24.    import mx.events.CollectionEventKind;
  25.    import mx.events.FlexNativeMenuEvent;
  26.    import mx.managers.ILayoutManagerClient;
  27.    import mx.managers.ISystemManager;
  28.    
  29.    use namespace mx_internal;
  30.    
  31.    public class FlexNativeMenu extends EventDispatcher implements ILayoutManagerClient, IFlexContextMenu
  32.    {
  33.       mx_internal static const VERSION:String = "3.5.0.12683";
  34.       
  35.       private static var MNEMONIC_INDEX_CHARACTER:String = "_";
  36.       
  37.       private var _labelField:String = "label";
  38.       
  39.       private var _initialized:Boolean = false;
  40.       
  41.       private var _keyEquivalentFunction:Function;
  42.       
  43.       private var keyEquivalentFieldChanged:Boolean = false;
  44.       
  45.       private var _mnemonicIndexFunction:Function;
  46.       
  47.       private var showRootChanged:Boolean = false;
  48.       
  49.       private var _mnemonicIndexField:String = "mnemonicIndex";
  50.       
  51.       private var invalidatePropertiesFlag:Boolean = false;
  52.       
  53.       private var _hasRoot:Boolean = false;
  54.       
  55.       private var labelFieldChanged:Boolean = false;
  56.       
  57.       private var _keyEquivalentModifiersFunction:Function = keyEquivalentModifiersDefaultFunction;
  58.       
  59.       private var dataProviderChanged:Boolean = false;
  60.       
  61.       private var _nestLevel:int = 1;
  62.       
  63.       private var _processedDescriptors:Boolean = false;
  64.       
  65.       private var _updateCompletePendingFlag:Boolean = false;
  66.       
  67.       private var mnemonicIndexFieldChanged:Boolean = false;
  68.       
  69.       private var _nativeMenu:NativeMenu = new NativeMenu();
  70.       
  71.       private var dataDescriptorChanged:Boolean = false;
  72.       
  73.       private var _dataDescriptor:IMenuDataDescriptor = new DefaultDataDescriptor();
  74.       
  75.       private var _showRoot:Boolean = true;
  76.       
  77.       mx_internal var _rootModel:ICollectionView;
  78.       
  79.       private var _labelFunction:Function;
  80.       
  81.       private var keyEquivalentModifiersFunctionChanged:Boolean = false;
  82.       
  83.       private var _keyEquivalentField:String = "keyEquivalent";
  84.       
  85.       public function FlexNativeMenu()
  86.       {
  87.          super();
  88.          _nativeMenu.addEventListener(Event.DISPLAYING,menuDisplayHandler,false,0,true);
  89.       }
  90.       
  91.       public function get nestLevel() : int
  92.       {
  93.          return _nestLevel;
  94.       }
  95.       
  96.       [Bindable("nativeMenuUpdate")]
  97.       public function get nativeMenu() : NativeMenu
  98.       {
  99.          return _nativeMenu;
  100.       }
  101.       
  102.       public function set nestLevel(param1:int) : void
  103.       {
  104.          _nestLevel = param1;
  105.          invalidateProperties();
  106.       }
  107.       
  108.       public function get updateCompletePendingFlag() : Boolean
  109.       {
  110.          return _updateCompletePendingFlag;
  111.       }
  112.       
  113.       [Bindable("mnemonicIndexFunctionChanged")]
  114.       public function get mnemonicIndexFunction() : Function
  115.       {
  116.          return _mnemonicIndexFunction;
  117.       }
  118.       
  119.       [Bindable("keyEquivalentFunctionChanged")]
  120.       public function get keyEquivalentFunction() : Function
  121.       {
  122.          return _keyEquivalentFunction;
  123.       }
  124.       
  125.       protected function parseLabelToMnemonicIndex(param1:String) : int
  126.       {
  127.          var _loc7_:String = null;
  128.          var _loc8_:int = 0;
  129.          var _loc2_:RegExp = new RegExp(MNEMONIC_INDEX_CHARACTER + MNEMONIC_INDEX_CHARACTER,"g");
  130.          var _loc3_:Array = param1.split(_loc2_);
  131.          var _loc4_:int = int(_loc3_.length);
  132.          var _loc5_:int = 0;
  133.          var _loc6_:int = 0;
  134.          while(_loc6_ < _loc4_)
  135.          {
  136.             _loc7_ = String(_loc3_[_loc6_]);
  137.             _loc8_ = int(_loc7_.indexOf(MNEMONIC_INDEX_CHARACTER));
  138.             if(_loc8_ >= 0)
  139.             {
  140.                return _loc8_ + _loc5_;
  141.             }
  142.             _loc5_ += _loc7_.length + MNEMONIC_INDEX_CHARACTER.length;
  143.             _loc6_++;
  144.          }
  145.          return -1;
  146.       }
  147.       
  148.       public function validateSize(param1:Boolean = false) : void
  149.       {
  150.       }
  151.       
  152.       public function set updateCompletePendingFlag(param1:Boolean) : void
  153.       {
  154.          _updateCompletePendingFlag = param1;
  155.       }
  156.       
  157.       private function clearMenu(param1:NativeMenu) : void
  158.       {
  159.          var _loc2_:int = int(param1.numItems);
  160.          var _loc3_:int = 0;
  161.          while(_loc3_ < _loc2_)
  162.          {
  163.             param1.removeItemAt(0);
  164.             _loc3_++;
  165.          }
  166.       }
  167.       
  168.       public function set mnemonicIndexFunction(param1:Function) : void
  169.       {
  170.          if(_mnemonicIndexFunction != param1)
  171.          {
  172.             _mnemonicIndexFunction = param1;
  173.             mnemonicIndexFieldChanged = true;
  174.             invalidateProperties();
  175.             dispatchEvent(new Event("mnemonicIndexFunctionChanged"));
  176.          }
  177.       }
  178.       
  179.       [Bindable("keyEquivalentChanged")]
  180.       public function get keyEquivalentField() : String
  181.       {
  182.          return _keyEquivalentField;
  183.       }
  184.       
  185.       public function set mnemonicIndexField(param1:String) : void
  186.       {
  187.          if(_mnemonicIndexField != param1)
  188.          {
  189.             _mnemonicIndexField = param1;
  190.             mnemonicIndexFieldChanged = true;
  191.             invalidateProperties();
  192.             dispatchEvent(new Event("mnemonicIndexFieldChanged"));
  193.          }
  194.       }
  195.       
  196.       private function itemSelectHandler(param1:Event) : void
  197.       {
  198.          var _loc5_:* = false;
  199.          var _loc2_:NativeMenuItem = param1.target as NativeMenuItem;
  200.          var _loc3_:String = dataDescriptor.getType(_loc2_.data).toLowerCase();
  201.          if(_loc3_ == "check")
  202.          {
  203.             _loc5_ = !dataDescriptor.isToggled(_loc2_.data);
  204.             _loc2_.checked = _loc5_;
  205.             dataDescriptor.setToggled(_loc2_.data,_loc5_);
  206.          }
  207.          var _loc4_:FlexNativeMenuEvent = new FlexNativeMenuEvent(FlexNativeMenuEvent.ITEM_CLICK);
  208.          _loc4_.nativeMenu = _loc2_.menu;
  209.          _loc4_.index = _loc2_.menu.getItemIndex(_loc2_);
  210.          _loc4_.nativeMenuItem = _loc2_;
  211.          _loc4_.label = _loc2_.label;
  212.          _loc4_.item = _loc2_.data;
  213.          dispatchEvent(_loc4_);
  214.       }
  215.       
  216.       [Bindable("keyEquivalentModifiersFunctionChanged")]
  217.       public function get keyEquivalentModifiersFunction() : Function
  218.       {
  219.          return _keyEquivalentModifiersFunction;
  220.       }
  221.       
  222.       public function set keyEquivalentFunction(param1:Function) : void
  223.       {
  224.          if(_keyEquivalentFunction != param1)
  225.          {
  226.             _keyEquivalentFunction = param1;
  227.             keyEquivalentFieldChanged = true;
  228.             invalidateProperties();
  229.             dispatchEvent(new Event("keyEquivalentFunctionChanged"));
  230.          }
  231.       }
  232.       
  233.       private function keyEquivalentModifiersDefaultFunction(param1:Object) : Array
  234.       {
  235.          var i:int = 0;
  236.          var modifier:* = undefined;
  237.          var data:Object = param1;
  238.          var modifiers:Array = [];
  239.          var xmlModifiers:Array = ["@altKey","@cmdKey","@ctrlKey","@shiftKey","@commandKey","@controlKey"];
  240.          var objectModifiers:Array = ["altKey","cmdKey","ctrlKey","shiftKey","commandKey","controlKey"];
  241.          var keyboardModifiers:Array = [Keyboard.ALTERNATE,Keyboard.COMMAND,Keyboard.CONTROL,Keyboard.SHIFT,Keyboard.COMMAND,Keyboard.CONTROL];
  242.          if(data is XML)
  243.          {
  244.             i = 0;
  245.             while(i < xmlModifiers.length)
  246.             {
  247.                try
  248.                {
  249.                   modifier = data[xmlModifiers[i]];
  250.                   if(modifier[0] == true)
  251.                   {
  252.                      modifiers.push(keyboardModifiers[i]);
  253.                   }
  254.                }
  255.                catch(e:Error)
  256.                {
  257.                }
  258.                i++;
  259.             }
  260.          }
  261.          else if(data is Object)
  262.          {
  263.             i = 0;
  264.             while(i < objectModifiers.length)
  265.             {
  266.                try
  267.                {
  268.                   modifier = data[objectModifiers[i]];
  269.                   if(String(modifier).toLowerCase() == "true")
  270.                   {
  271.                      modifiers.push(keyboardModifiers[i]);
  272.                   }
  273.                }
  274.                catch(e:Error)
  275.                {
  276.                }
  277.                i++;
  278.             }
  279.          }
  280.          return modifiers;
  281.       }
  282.       
  283.       private function menuDisplayHandler(param1:Event) : void
  284.       {
  285.          var _loc2_:NativeMenu = param1.target as NativeMenu;
  286.          var _loc3_:FlexNativeMenuEvent = new FlexNativeMenuEvent(FlexNativeMenuEvent.MENU_SHOW);
  287.          _loc3_.nativeMenu = _loc2_;
  288.          dispatchEvent(_loc3_);
  289.       }
  290.       
  291.       private function populateMenu(param1:NativeMenu, param2:ICollectionView) : NativeMenu
  292.       {
  293.          var menu:NativeMenu = param1;
  294.          var collection:ICollectionView = param2;
  295.          var collectionLength:int = collection.length;
  296.          var i:int = 0;
  297.          while(i < collectionLength)
  298.          {
  299.             try
  300.             {
  301.                insertMenuItem(menu,i,collection[i]);
  302.             }
  303.             catch(e:ItemPendingError)
  304.             {
  305.             }
  306.             i++;
  307.          }
  308.          return menu;
  309.       }
  310.       
  311.       public function set processedDescriptors(param1:Boolean) : void
  312.       {
  313.          _processedDescriptors = param1;
  314.       }
  315.       
  316.       [Bindable("labelFieldChanged")]
  317.       public function get labelField() : String
  318.       {
  319.          return _labelField;
  320.       }
  321.       
  322.       public function set dataDescriptor(param1:IMenuDataDescriptor) : void
  323.       {
  324.          _dataDescriptor = param1;
  325.          dataDescriptorChanged = true;
  326.       }
  327.       
  328.       private function createMenu() : NativeMenu
  329.       {
  330.          var _loc1_:NativeMenu = new NativeMenu();
  331.          _loc1_.addEventListener(Event.DISPLAYING,menuDisplayHandler,false,0,true);
  332.          return _loc1_;
  333.       }
  334.       
  335.       private function collectionChangeHandler(param1:CollectionEvent) : void
  336.       {
  337.          if(param1.kind == CollectionEventKind.ADD)
  338.          {
  339.             dataProviderChanged = true;
  340.             invalidateProperties();
  341.          }
  342.          else if(param1.kind == CollectionEventKind.REMOVE)
  343.          {
  344.             dataProviderChanged = true;
  345.             invalidateProperties();
  346.          }
  347.          else if(param1.kind == CollectionEventKind.REFRESH)
  348.          {
  349.             dataProviderChanged = true;
  350.             dataProvider = dataProvider;
  351.             invalidateProperties();
  352.          }
  353.          else if(param1.kind == CollectionEventKind.RESET)
  354.          {
  355.             dataProviderChanged = true;
  356.             invalidateProperties();
  357.          }
  358.          else if(param1.kind == CollectionEventKind.UPDATE)
  359.          {
  360.             dataProviderChanged = true;
  361.             invalidateProperties();
  362.          }
  363.       }
  364.       
  365.       public function set dataProvider(param1:Object) : void
  366.       {
  367.          var _loc3_:XMLList = null;
  368.          var _loc4_:Array = null;
  369.          if(mx_internal::_rootModel)
  370.          {
  371.             mx_internal::_rootModel.removeEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler);
  372.          }
  373.          if(typeof param1 == "string")
  374.          {
  375.             param1 = new XML(param1);
  376.          }
  377.          else if(param1 is XMLNode)
  378.          {
  379.             param1 = new XML(XMLNode(param1).toString());
  380.          }
  381.          else if(param1 is XMLList)
  382.          {
  383.             param1 = new XMLListCollection(param1 as XMLList);
  384.          }
  385.          if(param1 is XML)
  386.          {
  387.             _hasRoot = true;
  388.             _loc3_ = new XMLList();
  389.             _loc3_ += param1;
  390.             mx_internal::_rootModel = new XMLListCollection(_loc3_);
  391.          }
  392.          else if(param1 is ICollectionView)
  393.          {
  394.             mx_internal::_rootModel = ICollectionView(param1);
  395.             if(mx_internal::_rootModel.length == 1)
  396.             {
  397.                _hasRoot = true;
  398.             }
  399.          }
  400.          else if(param1 is Array)
  401.          {
  402.             mx_internal::_rootModel = new ArrayCollection(param1 as Array);
  403.          }
  404.          else if(param1 is Object)
  405.          {
  406.             _hasRoot = true;
  407.             _loc4_ = [];
  408.             _loc4_.push(param1);
  409.             mx_internal::_rootModel = new ArrayCollection(_loc4_);
  410.          }
  411.          else
  412.          {
  413.             mx_internal::_rootModel = new ArrayCollection();
  414.          }
  415.          mx_internal::_rootModel.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler,false,0,true);
  416.          dataProviderChanged = true;
  417.          invalidateProperties();
  418.          var _loc2_:CollectionEvent = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
  419.          _loc2_.kind = CollectionEventKind.RESET;
  420.          collectionChangeHandler(_loc2_);
  421.          dispatchEvent(_loc2_);
  422.       }
  423.       
  424.       public function get showRoot() : Boolean
  425.       {
  426.          return _showRoot;
  427.       }
  428.       
  429.       public function validateDisplayList() : void
  430.       {
  431.       }
  432.       
  433.       protected function parseLabelToString(param1:String) : String
  434.       {
  435.          var _loc7_:String = null;
  436.          var _loc2_:RegExp = new RegExp(MNEMONIC_INDEX_CHARACTER,"g");
  437.          var _loc3_:RegExp = new RegExp(MNEMONIC_INDEX_CHARACTER + MNEMONIC_INDEX_CHARACTER,"g");
  438.          var _loc4_:Array = param1.split(_loc3_);
  439.          var _loc5_:int = int(_loc4_.length);
  440.          var _loc6_:int = 0;
  441.          while(_loc6_ < _loc5_)
  442.          {
  443.             _loc7_ = String(_loc4_[_loc6_]);
  444.             _loc4_[_loc6_] = _loc7_.replace(_loc2_,"");
  445.             _loc6_++;
  446.          }
  447.          return _loc4_.join(MNEMONIC_INDEX_CHARACTER);
  448.       }
  449.       
  450.       public function set keyEquivalentModifiersFunction(param1:Function) : void
  451.       {
  452.          if(_keyEquivalentModifiersFunction != param1)
  453.          {
  454.             _keyEquivalentModifiersFunction = param1;
  455.             keyEquivalentModifiersFunctionChanged = true;
  456.             invalidateProperties();
  457.             dispatchEvent(new Event("keyEquivalentModifiersFunctionChanged"));
  458.          }
  459.       }
  460.       
  461.       public function get hasRoot() : Boolean
  462.       {
  463.          return _hasRoot;
  464.       }
  465.       
  466.       public function set keyEquivalentField(param1:String) : void
  467.       {
  468.          if(_keyEquivalentField != param1)
  469.          {
  470.             _keyEquivalentField = param1;
  471.             keyEquivalentFieldChanged = true;
  472.             invalidateProperties();
  473.             dispatchEvent(new Event("keyEquivalentFieldChanged"));
  474.          }
  475.       }
  476.       
  477.       protected function itemToLabel(param1:Object) : String
  478.       {
  479.          var data:Object = param1;
  480.          if(data == null)
  481.          {
  482.             return " ";
  483.          }
  484.          if(labelFunction != null)
  485.          {
  486.             return labelFunction(data);
  487.          }
  488.          if(data is XML)
  489.          {
  490.             try
  491.             {
  492.                if(data[labelField].length() != 0)
  493.                {
  494.                   data = data[labelField];
  495.                }
  496.             }
  497.             catch(e:Error)
  498.             {
  499.             }
  500.          }
  501.          else if(data is Object)
  502.          {
  503.             try
  504.             {
  505.                if(data[labelField] != null)
  506.                {
  507.                   data = data[labelField];
  508.                }
  509.             }
  510.             catch(e:Error)
  511.             {
  512.             }
  513.          }
  514.          else if(data is String)
  515.          {
  516.             return String(data);
  517.          }
  518.          try
  519.          {
  520.             return data.toString();
  521.          }
  522.          catch(e:Error)
  523.          {
  524.          }
  525.          return " ";
  526.       }
  527.       
  528.       public function set initialized(param1:Boolean) : void
  529.       {
  530.          _initialized = param1;
  531.       }
  532.       
  533.       [Bindable("mnemonicIndexChanged")]
  534.       public function get mnemonicIndexField() : String
  535.       {
  536.          return _mnemonicIndexField;
  537.       }
  538.       
  539.       public function get processedDescriptors() : Boolean
  540.       {
  541.          return _processedDescriptors;
  542.       }
  543.       
  544.       public function get dataDescriptor() : IMenuDataDescriptor
  545.       {
  546.          return IMenuDataDescriptor(_dataDescriptor);
  547.       }
  548.       
  549.       [Bindable("collectionChange")]
  550.       public function get dataProvider() : Object
  551.       {
  552.          if(mx_internal::_rootModel)
  553.          {
  554.             return mx_internal::_rootModel;
  555.          }
  556.          return null;
  557.       }
  558.       
  559.       public function display(param1:Stage, param2:int, param3:int) : void
  560.       {
  561.          nativeMenu.display(param1,param2,param3);
  562.       }
  563.       
  564.       protected function commitProperties() : void
  565.       {
  566.          var _loc1_:ICollectionView = null;
  567.          var _loc2_:* = undefined;
  568.          if(showRootChanged)
  569.          {
  570.             if(!_hasRoot)
  571.             {
  572.                showRootChanged = false;
  573.             }
  574.          }
  575.          if(dataProviderChanged || showRootChanged || labelFieldChanged || dataDescriptorChanged)
  576.          {
  577.             dataProviderChanged = false;
  578.             showRootChanged = false;
  579.             labelFieldChanged = false;
  580.             dataDescriptorChanged = false;
  581.             if(mx_internal::_rootModel && !_showRoot && _hasRoot)
  582.             {
  583.                _loc2_ = mx_internal::_rootModel.createCursor().current;
  584.                if(_loc2_ != null && _dataDescriptor.isBranch(_loc2_,mx_internal::_rootModel) && _dataDescriptor.hasChildren(_loc2_,mx_internal::_rootModel))
  585.                {
  586.                   _loc1_ = _dataDescriptor.getChildren(_loc2_,mx_internal::_rootModel);
  587.                }
  588.             }
  589.             clearMenu(_nativeMenu);
  590.             if(mx_internal::_rootModel)
  591.             {
  592.                if(!_loc1_)
  593.                {
  594.                   _loc1_ = mx_internal::_rootModel;
  595.                }
  596.                _loc1_.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler,false,EventPriority.DEFAULT_HANDLER,true);
  597.                populateMenu(_nativeMenu,_loc1_);
  598.             }
  599.             dispatchEvent(new Event("nativeMenuChange"));
  600.          }
  601.       }
  602.       
  603.       public function unsetContextMenu(param1:InteractiveObject) : void
  604.       {
  605.          param1.contextMenu = null;
  606.       }
  607.       
  608.       public function invalidateProperties() : void
  609.       {
  610.          var _loc1_:Timer = null;
  611.          if(!invalidatePropertiesFlag && nestLevel > 0)
  612.          {
  613.             invalidatePropertiesFlag = true;
  614.             if(UIComponentGlobals.mx_internal::layoutManager)
  615.             {
  616.                UIComponentGlobals.mx_internal::layoutManager.invalidateProperties(this);
  617.             }
  618.             else
  619.             {
  620.                _loc1_ = new Timer(100,1);
  621.                _loc1_.addEventListener(TimerEvent.TIMER,validatePropertiesTimerHandler);
  622.                _loc1_.start();
  623.             }
  624.          }
  625.       }
  626.       
  627.       public function set labelField(param1:String) : void
  628.       {
  629.          if(_labelField != param1)
  630.          {
  631.             _labelField = param1;
  632.             labelFieldChanged = true;
  633.             invalidateProperties();
  634.             dispatchEvent(new Event("labelFieldChanged"));
  635.          }
  636.       }
  637.       
  638.       public function get initialized() : Boolean
  639.       {
  640.          return _initialized;
  641.       }
  642.       
  643.       public function validatePropertiesTimerHandler(param1:TimerEvent) : void
  644.       {
  645.          validateProperties();
  646.       }
  647.       
  648.       public function set labelFunction(param1:Function) : void
  649.       {
  650.          if(_labelFunction != param1)
  651.          {
  652.             _labelFunction = param1;
  653.             labelFieldChanged = true;
  654.             invalidateProperties();
  655.             dispatchEvent(new Event("labelFunctionChanged"));
  656.          }
  657.       }
  658.       
  659.       protected function itemToKeyEquivalentModifiers(param1:Object) : Array
  660.       {
  661.          if(param1 == null)
  662.          {
  663.             return [];
  664.          }
  665.          if(keyEquivalentModifiersFunction != null)
  666.          {
  667.             return keyEquivalentModifiersFunction(param1);
  668.          }
  669.          return [];
  670.       }
  671.       
  672.       protected function itemToKeyEquivalent(param1:Object) : String
  673.       {
  674.          var data:Object = param1;
  675.          if(data == null)
  676.          {
  677.             return "";
  678.          }
  679.          if(keyEquivalentFunction != null)
  680.          {
  681.             return keyEquivalentFunction(data);
  682.          }
  683.          if(data is XML)
  684.          {
  685.             try
  686.             {
  687.                if(data[keyEquivalentField].length() != 0)
  688.                {
  689.                   data = data[keyEquivalentField];
  690.                   return data.toString();
  691.                }
  692.             }
  693.             catch(e:Error)
  694.             {
  695.             }
  696.          }
  697.          else if(data is Object)
  698.          {
  699.             try
  700.             {
  701.                if(data[keyEquivalentField] != null)
  702.                {
  703.                   data = data[keyEquivalentField];
  704.                   return data.toString();
  705.                }
  706.             }
  707.             catch(e:Error)
  708.             {
  709.             }
  710.          }
  711.          return "";
  712.       }
  713.       
  714.       public function validateNow() : void
  715.       {
  716.          if(invalidatePropertiesFlag)
  717.          {
  718.             validateProperties();
  719.          }
  720.       }
  721.       
  722.       private function insertMenuItem(param1:NativeMenu, param2:int, param3:Object) : void
  723.       {
  724.          var _loc7_:String = null;
  725.          var _loc8_:int = 0;
  726.          if(dataProviderChanged)
  727.          {
  728.             commitProperties();
  729.             return;
  730.          }
  731.          var _loc4_:String = dataDescriptor.getType(param3).toLowerCase();
  732.          var _loc5_:* = _loc4_ == "separator";
  733.          var _loc6_:NativeMenuItem = new NativeMenuItem("",_loc5_);
  734.          if(!_loc5_)
  735.          {
  736.             _loc6_.enabled = dataDescriptor.isEnabled(param3);
  737.             _loc6_.checked = _loc4_ == "check" && dataDescriptor.isToggled(param3);
  738.             _loc6_.data = dataDescriptor.getData(param3,mx_internal::_rootModel);
  739.             _loc6_.keyEquivalent = itemToKeyEquivalent(param3);
  740.             _loc6_.keyEquivalentModifiers = itemToKeyEquivalentModifiers(param3);
  741.             _loc7_ = itemToLabel(param3);
  742.             _loc8_ = itemToMnemonicIndex(param3);
  743.             if(_loc8_ >= 0)
  744.             {
  745.                _loc6_.label = parseLabelToString(_loc7_);
  746.                _loc6_.mnemonicIndex = _loc8_;
  747.             }
  748.             else
  749.             {
  750.                _loc6_.label = parseLabelToString(_loc7_);
  751.                _loc6_.mnemonicIndex = parseLabelToMnemonicIndex(_loc7_);
  752.             }
  753.             _loc6_.addEventListener(Event.SELECT,itemSelectHandler,false,0,true);
  754.             if(dataDescriptor.isBranch(param3,mx_internal::_rootModel) && dataDescriptor.hasChildren(param3,mx_internal::_rootModel))
  755.             {
  756.                _loc6_.submenu = createMenu();
  757.                populateMenu(_loc6_.submenu,dataDescriptor.getChildren(param3,mx_internal::_rootModel));
  758.             }
  759.          }
  760.          param1.addItem(_loc6_);
  761.       }
  762.       
  763.       public function setContextMenu(param1:InteractiveObject) : void
  764.       {
  765.          var _loc2_:ISystemManager = null;
  766.          param1.contextMenu = nativeMenu;
  767.          if(param1 is Application)
  768.          {
  769.             _loc2_ = Application(param1).systemManager;
  770.             if(_loc2_ is InteractiveObject)
  771.             {
  772.                InteractiveObject(_loc2_).contextMenu = nativeMenu;
  773.             }
  774.          }
  775.       }
  776.       
  777.       protected function itemToMnemonicIndex(param1:Object) : int
  778.       {
  779.          var mnemonicIndex:int = 0;
  780.          var data:Object = param1;
  781.          if(data == null)
  782.          {
  783.             return -1;
  784.          }
  785.          if(mnemonicIndexFunction != null)
  786.          {
  787.             return mnemonicIndexFunction(data);
  788.          }
  789.          if(data is XML)
  790.          {
  791.             try
  792.             {
  793.                if(data[mnemonicIndexField].length() != 0)
  794.                {
  795.                   mnemonicIndex = int(data[mnemonicIndexField]);
  796.                   return mnemonicIndex;
  797.                }
  798.             }
  799.             catch(e:Error)
  800.             {
  801.             }
  802.          }
  803.          else if(data is Object)
  804.          {
  805.             try
  806.             {
  807.                if(data[mnemonicIndexField] != null)
  808.                {
  809.                   mnemonicIndex = int(data[mnemonicIndexField]);
  810.                   return mnemonicIndex;
  811.                }
  812.             }
  813.             catch(e:Error)
  814.             {
  815.             }
  816.          }
  817.          return -1;
  818.       }
  819.       
  820.       public function validateProperties() : void
  821.       {
  822.          if(invalidatePropertiesFlag)
  823.          {
  824.             commitProperties();
  825.             invalidatePropertiesFlag = false;
  826.          }
  827.       }
  828.       
  829.       [Bindable("labelFunctionChanged")]
  830.       public function get labelFunction() : Function
  831.       {
  832.          return _labelFunction;
  833.       }
  834.       
  835.       public function set showRoot(param1:Boolean) : void
  836.       {
  837.          if(_showRoot != param1)
  838.          {
  839.             showRootChanged = true;
  840.             _showRoot = param1;
  841.             invalidateProperties();
  842.          }
  843.       }
  844.    }
  845. }
  846.  
  847.