Flex 4.5:仅在应用程序打开时单击并单击按钮

时间:2012-02-13 16:04:25

标签: actionscript-3 flex flex4.5 flexbuilder

我根据教程之一开发了小型RSS阅读器。这是一个简单的应用程序,在HomeView上,当用户单击RSS项目的标题,然后在DetailsView.mxml上的app推送视图。但我有一个小问题。我在HomeView上包含一个刷新按钮,但每次当我滚动列表或单击项目然后返回HomeView列表时都会刷新。这使用了很多互联网连接。有可能使这个应用程序,以便当应用程序打开时,然后加载(刷新)列表然后刷新只按下按钮“刷新”?

P.S。拜托,我需要简单的解释,我不是程序员:)

感谢您的帮助,这里是HomeView的源代码:

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:rssreader="services.rssreader.*"
        xmlns:s="library://ns.adobe.com/flex/spark"
        title="Elektro-Vozila" viewActivate="getData()">

    <fx:Script>
        <![CDATA[
            import spark.events.IndexChangeEvent;

            protected function getData():void
            {
                getDataResult.token = rssreader.getData();
            }

            import mx.events.CollectionEvent;
            import valueObjects.Item;

            protected function fixEntityReferences(event:CollectionEvent):void
            {
                myList.labelFunction = replaceEntity;

                function replaceEntity(item:Item):String
                {
                    var p1:RegExp = /(&quot;)/ig; // perhaps add more here later
                    var thisString:String = item.title.replace(p1, "");
                    trace(thisString);
                    return thisString;

                }
            }

            protected function myList_changeHandler(event:IndexChangeEvent):void
            {

                var RSSItem:Object = myList.dataProvider.getItemAt(event.newIndex);
                navigator.pushView(DetailsView, RSSItem);
            }

            private function refreshList():void

            {

                    Object(navigator.activeView).getData();  

            }
        ]]>

    </fx:Script>
    <s:actionContent>
        <s:Button label="Refresh"
                  click="refreshList()"/>
    </s:actionContent>
    <fx:Declarations>
        <s:CallResponder id="getDataResult"/>
        <rssreader:Rssreader id="rssreader"/>
        <s:CallResponder id="getDataResult2"/>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:List bottom="0"
            change="myList_changeHandler(event)"
            id="myList"
            itemRenderer="views.IconItemRenderer"
            labelField="title"
            left="0"
            right="0"
            top="0">
        <s:AsyncListView list="{getDataResult.lastResult}"
                         collectionChange="fixEntityReferences(event)"/>

    </s:List>
</s:View>

1 个答案:

答案 0 :(得分:0)

嗨Roky,

        private var dataLoaded : Boolean = false;

        protected function getData(force : Boolean = false) : void
        {
            if (!dataLoaded || force)
            {
                getDataResult.token = rssreader.getData();
                dataLoaded = true;
            }
        }

在刷新按钮中,即使数据已经加载,也可以调用getData(true)强制刷新它。