tags:

views:

279

answers:

4

in main.mxml :

    public function init():void
    {
       PopUpManager.createPopUp(this,login,true);
    }
    <mx:ViewStack id="vs" label="content" >
      <local:FrontPanel id="Fpanel" />
      <local:SlavePanel id="Spanel" />
      <local:AdminPanel id="Mpanel" />  
    </mx:ViewStack>

In Login.mxml :

public function authenticateRH(event:ResultEvent):void
    {
     var replyMsg:String=event.result as String;  

     switch(replyMsg)
     {
      case "Master" :
       here i want invoke Mpanel from Main.mxml
       break;

      case "Slave" :
              here i want invoke Spanel from Main.mxml 
       break;

      case "fail" :
       Alert.show("Login Incorrect!!");
       return;
     }      
   }

How can i selectchild of main.mxml's Viewstack from login.mxml ?

A: 

I'm assuming your problem is that you don't have a reference to your ViewStack while in your authenticateRH method. One way you can fix this is to give your login popup some more information after you create it:

public function init():void
{
    var loginPopup:login = PopUpManager.createPopUp(this,login,true) as login;                                      
    loginPopup.setUsefulInformation(referenceToViewStack);
}

You'd have to add the setUsefulInformation() method to login.mxml. It's up to you what information you want to pass to solve the problem.

Wesley Petrowski
A: 

first, i believe you're creating your pop-up incorrectly. you seem to have the first two parameters switched. should be:

PopUpManager.createPopUp(login,this,true);
docs: http://livedocs.adobe.com/flex/3/langref/mx/managers/PopUpManager.html#addPopUp%28%29

second, you need to either explicitly give your Login class a reference to your Main class or if your Login class is on the same display chain as your Main class you can use a custom event with Bubbles set to true.

greg
+1  A: 

I would use events (and interfaces), that way your forms don't need to know as much about one and other. It also gives you more control on what happens after your popup closes (IMHO).

Here is a little example (if I can get the code to paste correctly). This example does not use an interface that would help decouple things. I also use dynamic events that make prototyping faster but you will want to define a formal event.

simulate your main:

     import mx.events.DynamicEvent;
 import mx.managers.PopUpManager;

 private function btnClick(e:Event):void
 {
  vs.selectedIndex = 0;

  var myLogin:myPopup = new myPopup();
  myLogin.addEventListener
    (
     "WAS_CLOSED",
     function(e:DynamicEvent):void { vs.selectedIndex = e.byButton; }
    );

  PopUpManager.addPopUp(myLogin, this, true);
  PopUpManager.centerPopUp(myLogin);
 }

simulate your login:

     import mx.events.DynamicEvent;
 import mx.managers.PopUpManager;

 private var eClose:DynamicEvent = new DynamicEvent("WAS_CLOSED");

 private function closeMe(byButton:int):void
 {
  eClose.byButton = byButton;
  dispatchEvent(eClose);
  PopUpManager.removePopUp(this);
 }

<mx:Button x="122" y="250" label="Thing 1" click="closeMe(1);" />
<mx:Button x="195" y="250" label="Thing 2" click="closeMe(2);" />
Jon.Stromer.Galley
+1  A: 
public function init():void
{
   var popup:IFlexDisplayObject = PopUpManager.createPopUp(this, Login, true);
   popup.addEventListener(Event.SELECT, onSelect);
}
private function onSelect(e:CustomEvent):void
{
    if(e.item == CustomEvent.MASTER)
    {
        vs.selectedItem = Mpanel;
    }
    else if(e.item == CustomEvent.SLAVE)
    {
        vs.selectedItem = Spanel;
    }
    //remove popup
    PopUpManager.removePopUp(IFlexDisplayObject(e.target));
}

//Login.mxml :
public function authenticateRH(event:ResultEvent):void
{
    var replyMsg:String=event.result as String;             

    switch(replyMsg)
    {
            case "Master" :
                    dispatchEvent(new CustomEvent(CustomEvent.MASTER));
                    break;

            case "Slave" :
                    dispatchEvent(new CustomEvent(CustomEvent.MASTER));
                    break;
            case "fail" :
                    //remove popup
                    PopUpManager.removePopUp(this);
                    Alert.show("Login Incorrect!!");
                    return;
    }      
}
//CustomEvent.as
public class CustomEvent extends Event
{
    public static const MASTER:String = "master";
    public static const SLAVE:String = "slave";
    public var item:String;
    public function CustomEvent(item:String)
    {
        super(Event.SELECT);
        this.item = item;
    }
}
Amarghosh
@AmarGhosh, thanks dear, hey cud u suggest me this..developing felx app as tow different applications is good or making two module in one application is good ?
Thirst for Excellence