1 Reply Latest reply on Jan 14, 2008 7:33 AM by manuel_cfe

    Menu by user type

    manuel_cfe
      I want a menubar by type of user in my application,
      As I do this?.
      I currently have this

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

      <!-- mx:Style source="/style/estilo1.css"/> -->
      <mx:Script>
      <![CDATA[
      //import mx.managers.HistoryManager;
      import mx.controls.Menu;
      import mx.events.MenuEvent;
      import mx.controls.Alert;
      import mx.rpc.events.ResultEvent;
      import mx.collections.XMLListCollection;
      // import mx.collections.ArrayCollection;
      [Bindable]
      public var datos:XMLList;

      private function httpResult(event:ResultEvent):void{
      var miXML:XML;
      miXML = event.result as XML;
      datos = new XMLList(miXML.menuitem);
      }

      private function initModule(modulo:String):void {

      var s:String = modulo

      m1.url = s;
      }



      // Event handler for the Menu control's change event.
      private function menuHandler(event:MenuEvent):void {
      //Alert.show("Label: " + event.item.@label, "Clicked menu item");
      if (event.item.@label == "Programado"){
      initModule("datosb.swf");
      }
      if (event.item.@label == "Real"){
      initModule("valores.swf");
      }
      }
      ]]>
      </mx:Script>
      <mx:states>
      <mx:State name="Logged In">
      <mx:SetProperty target="{panel1}" name="width" value="100%"/>
      <mx:SetProperty target="{panel1}" name="height" value="100%"/>
      <mx:RemoveChild target="{password}"/>
      <mx:RemoveChild target="{username}"/>
      <mx:RemoveChild target="{label1}"/>
      <mx:RemoveChild target="{Submit}"/>
      <mx:RemoveChild target="{label2}"/>
      <mx:SetProperty target="{panel1}" name="title" value="CLIPRO"/>
      <mx:AddChild relativeTo="{panel1}" position="lastChild">
      <mx:Label x="0" text="Bienvenido al sistema!" fontSize="9" width="127" bottom="1"/>
      </mx:AddChild>
      <mx:AddChild relativeTo="{panel1}" position="lastChild">
      <mx:Label x="120" id="nombre" fontSize="9" bottom="1"/>

      </mx:AddChild>
      <mx:AddChild relativeTo="{panel1}" position="lastChild">

      </mx:AddChild>
      <mx:AddChild relativeTo="{panel1}" position="lastChild">
      <mx:MenuBar id="menuA" dataProvider="{datos}" itemClick="menuHandler(event)" labelField="@label" height="22" x="0" y="0" width="100%"></mx:MenuBar>
      </mx:AddChild>
      <mx:AddChild relativeTo="{panel1}" position="lastChild">
      <mx:ModuleLoader id="m1" horizontalCenter="0" verticalCenter="-84"/>
      </mx:AddChild>
      </mx:State>
      </mx:states>
      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;

      ]]>
      </mx:Script>
      <mx:Script>


      <![CDATA[
      [Bindable]
      public var usermenu:String;

      private function checkLogin(evt:ResultEvent):void{

      if(evt.result.loginsuccess == "yes") {
      currentState = "Logged In";
      initialize="cargaMenu.send()"
      if(evt.result.tipo == "admin") {
      this.usermenu = " http://..../clipro/xml/menuadmin.xml";
      nombre.text = evt.result.usuario + ' '+usermenu;
      }
      if(evt.result.tipo == "normal") {
      this.usermenu = " http://..../clipro/xml/menunormal.xml";
      nombre.text = evt.result.usuario + ' '+usermenu;
      }

      }

      if(evt.result.loginsuccess == "no") {
      mx.controls.Alert.show('Usuario o password invalido');
      }
      }

      ]]>

      </mx:Script>
      <mx:HTTPService id="login_user" result="checkLogin(event)" showBusyCursor="true" method="POST" url=" http://.../clipro/php/login.php" useProxy="false">
      <mx:request xmlns="">
      <username>{username.text}</username>
      <password>{password.text}</password>
      </mx:request>
      </mx:HTTPService>

      <mx:HTTPService id="cargaMenu" showBusyCursor="true" method="POST" url="{usermenu}"
      result="httpResult(event)" resultFormat="object"/>

      <mx:Panel resizeEffect="Resize" width="250" height="200" layout="absolute" title="Acceso Restringido" horizontalCenter="0" verticalCenter="-2" id="panel1">
      <mx:Label x="10" y="10" text="Usuario" id="label1"/>
      <mx:TextInput x="10" y="36" id="username" editable="true" enabled="true" toolTip="RPE"/>
      <mx:Label x="10" y="66" text="Password:" id="label2"/>
      <mx:TextInput x="10" y="92" id="password" displayAsPassword="true"/>
      <mx:Button x="10" y="122" label="Entrar" id="Submit" click="login_user.send()"/>
      </mx:Panel>

      </mx:Application>