如何使用ArrayList导航到动态视图

时间:2012-06-27 13:04:22

标签: flex flash-builder flex4.5

抱歉我的英语不好。 我上了几个小时,但我找不到解决问题的方法。

我想从DataProvider中的arrayList获取视图名称,将我的视图导航到另一个视图。

如何获取点击项目的网址并导航为视图。 感谢..

<s:List id="listMenu" top="0" bottom="0" left="0" right="0" height="100%" width="100%" 
click="navigator.pushView(listMenu.url as View)">
<s:dataProvider>
    <s:ArrayList>
        <fx:Object name="Title1" detail="Detail1" src="@Embed('../media/graphics/credit-card.png')" url="View1" />
        <fx:Object name="Title2 Sorgulama" detail="Detail2" src="@Embed('../media/graphics/IMEI.png')" url="View2" />       
    </s:ArrayList>
</s:dataProvider>
<s:itemRenderer>
    <fx:Component>
        <s:IconItemRenderer labelField="name" messageField="detail" iconField="src" iconWidth="64" iconHeight="64" height="68" />               
    </fx:Component>
</s:itemRenderer>

1 个答案:

答案 0 :(得分:0)

你去吧 -

<强>资产/图标/ FB.png:

enter image description here

<强>资产/图标/ GG.png:

enter image description here

<强>视图/ Home.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark">

    <fx:Script>
        <![CDATA[
            import mx.core.BitmapAsset;
            import mx.events.FlexEvent;

            import spark.components.SplitViewNavigator;
            import spark.components.ViewNavigator;
            import spark.core.SpriteVisualElement;
            import spark.events.IndexChangeEvent;

            [Embed(source="assets/icons/FB.png")] 
            private static const FB_CLASS:Class;
            [Embed(source="assets/icons/GG.png")] 
            private static const GG_CLASS:Class;

            private static const FB_ICON:BitmapAsset = new FB_CLASS() as BitmapAsset;
            private static const GG_ICON:BitmapAsset = new GG_CLASS() as BitmapAsset;

            protected function handleChange(event:IndexChangeEvent):void {
                var item:Object = login.selectedItem;
                navigator.pushView(item.view, item.str);
            }
        ]]>
    </fx:Script>    

    <s:List width="100%" height="100%" id="login" change="handleChange(event);">
        <s:dataProvider> 
            <s:ArrayCollection> 
                <fx:Object icon="{FB_ICON}" view="{FB}" label="Play at" msg="Facebook.com" /> 
                <fx:Object icon="{GG_ICON}" view="{GG}" label="Play at" msg="Google+" /> 
            </s:ArrayCollection> 
        </s:dataProvider>
        <s:itemRenderer>
            <fx:Component>
                <s:IconItemRenderer labelField="label" iconField="icon" messageField="msg"/>
            </fx:Component>
        </s:itemRenderer>
    </s:List>
</s:View>

<强> App.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    firstView="views.Home">
</s:ViewNavigatorApplication>

上面引用的 views / FB.mxml views / GG.mxml - 由您自己创建; - )