简体   繁体   English

Flex:视图堆栈导航器

[英]Flex: View Stack Navigator

I have a component mxml file in which i have a view stack, on click of a button i navigate to the first child, now i need to navigate to the second child during onclick of a button present in the second child. 我有一个组件mxml文件,其中有一个视图堆栈,单击按钮时便导航到第一个孩子,现在我需要在第二个孩子中存在的按钮的onclick期间导航到第二个孩子。 All the childs are component files included within the view stack. 所有子项都是视图堆栈中包含的组件文件。 How could this be done, Sample code is present below, 如何做到这一点,下面是示例代码,

--------------------Application.mxml--------------------- -------------------- Application.mxml ---------------------

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" >
    <mx:Script>
        <![CDATA[
             private function loadScreen():void
             {
                navigationViewStack.selectedChild=id_offering;  
             }
        ]]>
    </mx:Script>

     <mx:Button label="Save" click="loadScreen();"/>

 </mx:Canvas>

<mx:ViewStack id="navigationViewStack"  width="100%" height="100%">
    <components:dashboard   id="id_dashboard" label="Dashboard" />
    <components:offering   id="id_offering" label="Offering" />
    <components:IssueSec id="id_issueSec" label = "Issues"/>
</mx:ViewStack>

-------------------------Ends-------------------------------------- -------------------------结束------------------------ --------------

Now in my offering.mxml file if i try to access navigationViewStack i am getting an error stating 'Access of undefined property navigationViewStack. 现在,在我的provision.mxml文件中,如果我尝试访问navigationViewStack,则会收到一条错误消息,指出“访问未定义的属性navigationViewStack。

Help me on how to access the view stack from my component mxml file. 帮助我如何从组件mxml文件访问视图堆栈。

Thanks! 谢谢!

Cheers, Deena 干杯,迪娜

Offering.mxml does not have access to navigationViewStack as it is a property inside your Application.mxml file. Offering.mxml无权访问navigationViewStack,因为它是Application.mxml文件中的一个属性。 You'll need to dispatch an event from inside of offering.xml, Application.mxml will listen for that event, and handle it by switching to the appropriate view stack element. 您需要从office.xml内部调度一个事件,Application.mxml将侦听该事件,并通过切换到适当的视图堆栈元素来处理该事件。

If you're not familiar with custom events, read this: 如果您不熟悉自定义事件,请阅读以下内容:

http://livedocs.adobe.com/flex/3/html/help.html?content=createevents_3.html http://livedocs.adobe.com/flex/3/html/help.html?content=createevents_3.html

Custom events is the answer for your question. 自定义事件是您问题的答案。 Its simple have a look at this example 简单看看这个例子

http://flexblog.faratasystems.com/2007/02/26/event-driven-programming-in-flex-with-custom-events http://flexblog.faratasystems.com/2007/02/26/event-driven-programming-in-flex-with-custom-events

Custom event is the correct and appropriate way to go; 自定义事件是正确而适当的方式; if you want a quick and dirty solution that will eventually become difficult to maintain as your code base grow, you can try this from the button click handler in the Offering.mxml : 如果你想快速和肮脏的解决方案,最终将变得难以维护的代码库的成长,你可以从按钮单击处理程序试试这个Offering.mxml

ViewStack(this.parent).selectedIndex = 2; //2 for IssueSec 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM