在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?
答案 0 :(得分:1)
我会使用事件(和接口),这样你的表单就不需要了解其中的一个。它还可以让您更好地控制弹出窗口关闭后发生的事情(恕我直言)。
这是一个小例子(如果我可以正确粘贴代码)。此示例不使用有助于解耦事物的接口。我还使用动态事件来加快原型设计,但是你需要定义一个正式的事件。
模拟你的主要:
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);" />
答案 1 :(得分:1)
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;
}
}
答案 2 :(得分:0)
我假设你的问题是你在authenticateRH方法中没有对你的ViewStack的引用。解决此问题的一种方法是在创建登录后弹出更多信息:
public function init():void
{
var loginPopup:login = PopUpManager.createPopUp(this,login,true) as login;
loginPopup.setUsefulInformation(referenceToViewStack);
}
您必须将setUsefulInformation()方法添加到login.mxml。由您决定要传递哪些信息来解决问题。
答案 3 :(得分:0)
首先,我相信你错误地创建了弹出窗口。你似乎已经切换了前两个参数。应该是:
PopUpManager.createPopUp(login,this,true);
docs:http://livedocs.adobe.com/flex/3/langref/mx/managers/PopUpManager.html#addPopUp%28%29
第二,您需要明确地为您的Login类提供对Main类的引用,或者如果您的Login类与Main类位于同一显示链上,则可以使用Bubbles
设置为{的自定义事件{1}}。