如何在视图堆栈中设置选定的子项?

发布于 2024-08-13 04:10:14 字数 955 浏览 3 评论 0原文

在 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> 

在 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;
        }      
   }

如何从 login.mxml 中选择 main.mxml 的 Viewstack 的子项?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ヤ经典坏疍 2024-08-20 04:10:14

我会使用事件(和接口),这样您的表单就不需要了解太多有关其中一个或另一个的信息。它还可以让您更好地控制弹出窗口关闭后发生的情况(恕我直言)。

这是一个小例子(如果我可以正确粘贴代码)。此示例不使用有助于解耦事物的接口。我还使用动态事件来加快原型设计速度,但您需要定义一个正式事件。

模拟您的主要:

        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);
    }

模拟您的登录:

        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);" />

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);" />
离笑几人歌 2024-08-20 04:10:14
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;
    }
}
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;
    }
}
小帐篷 2024-08-20 04:10:14

我假设您的问题是在您的authenticateRH 方法中没有对ViewStack 的引用。解决此问题的一种方法是在创建登录弹出窗口后为其提供更多信息:

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

您必须将 setUsefulInformation() 方法添加到 login.mxml。由您决定要传递哪些信息来解决问题。

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.

吝吻 2024-08-20 04:10:14

首先,我相信您创建的弹出窗口不正确。您似乎已切换前两个参数。应该是:

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

其次,您需要显式为您的 Login 类提供对 Main 类的引用,或者如果您的 Login 类是在与 Main 类相同的显示链上,您可以使用将 Bubbles 设置为 true 的自定义事件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文