iconitemrenderer可点击的对象?

时间:2011-06-29 12:41:53

标签: android flex mxml itemrenderer navigator

我正在使用Flash Builder 4.5为Android和iOS制作移动应用程序,并使用itemRenderer和iconitemrenderer类为我的应用程序制作选项列表。出于某种原因,我无法使它们可单击,或者定义单击每个时要执行的操作。基本上,我的目标是使用FB的“视图”,当单击一个项目时,切换到新视图。这是我正在使用的代码:

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:ms="libs/MessageBox-digitalRetro">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:actionContent>
        <s:Button id="signin" label="Sign in" click="onSignIn(event)"/>
    </s:actionContent>
        //code for the clicking of the sign in button
    <fx:Script>
        <![CDATA[
            protected function onSignIn(event:Event):void
            {

            }
        ]]>
    </fx:Script>
    <s:List height="100%" width="100%">
        <s:itemRenderer>
            <fx:Component>
                <s:IconItemRenderer height="100" labelField="name" 
                                    iconField="photo" iconHeight="80" 
                                    iconWidth="80" messageFunction="getMessage">
                    <fx:Script>
                        <![CDATA[
                            import spark.components.NavigatorContent;
                                                    //this first method works
                            protected function getMessage(o:Object):String
                            {
                                return o.message;
                            }
                        ]]>
                    </fx:Script>
                </s:IconItemRenderer>
            </fx:Component>
        </s:itemRenderer>
        <s:dataProvider>
            <s:ArrayCollection>
                <fx:Object name="Projects" photo="@Embed('libs/ProjectsIcon2.png')" message="Learn more about what we're working on" clickfn="views/Projects"/>
                <fx:Object name="Locate Office" photo="@Embed('libs/google-maps-icon.png')" message="Find directions to our nearest office" clickfn=""/>
                <fx:Object name="Contact Us" photo="@Embed('libs/gmailicon.png')" message="Let us know your thoughts!" clickfn=""/>
                <fx:Object name="About Us" photo="@Embed('libs/info-icon.png')" message="" clickfn=""/>
            </s:ArrayCollection>
        </s:dataProvider>
            <s:change>
        <![CDATA[
                // NEW!!!
            var ClassReference:Class = getDefinitionByName(event.currentTarget.selectedItem.clickfn) as Class;
            navigator.pushView(ClassReference);
        ]]>
    </s:change>
    </s:List>
</s:View>

编辑:我添加了“更改”标签,现在编译,但我收到一条错误消息:

ReferenceError:错误#1065:未定义变量项目。     at global / flash.utils :: getDefinitionByName()     at views :: MainHomeView / ___ MainHomeView_List1_change()[C:\ Users \ jlehenbauer \ Adob​​e Flash Builder 4.5 \ Metters Inc \ src \ views \ MainHomeView.mxml:56]     在flash.events::EventDispatcher/dispatchEventFunction()     at flash.events::EventDispatcher/dispatchEvent()     at mx.core :: UIComponent / dispatchEvent()[E:\ dev \ 4.5.1 \ frameworks \ projects \ framework \ src \ mx \ core \ UIComponent.as:13128]     在spark.components :: List / commitSelection()[E:\ dev \ 4.5.1 \ frameworks \ projects \ spark \ src \ spark \ components \ List.as:1205]     在spark.components.supportClasses :: ListBase / commitProperties()[E:\ dev \ 4.5.1 \ frameworks \ projects \ spark \ src \ spark \ components \ supportClasses \ ListBase.as:939]     在spark.components :: List / commitProperties()[E:\ dev \ 4.5.1 \ frameworks \ projects \ spark \ src \ spark \ components \ List.as:1069]     at mx.core :: UIComponent / validateProperties()[E:\ dev \ 4.5.1 \ frameworks \ projects \ framework \ src \ mx \ core \ UIComponent.as:8209]     在mx.managers :: LayoutManager / validateProperties()[E:\ dev \ 4.5.1 \ frameworks \ projects \ framework \ src \ mx \ managers \ LayoutManager.as:597]     在mx.managers :: LayoutManager / doPhasedInstantiation()[E:\ dev \ 4.5.1 \ frameworks \ projects \ framework \ src \ mx \ managers \ LayoutManager.as:813]     在mx.managers :: LayoutManager / doPhasedInstantiationCallback()[E:\ dev \ 4.5.1 \ frameworks \ projects \ framework \ src \ mx \ managers \ LayoutManager.as:1180]

4 个答案:

答案 0 :(得分:1)

  

我正在制作移动应用程序   适用于Android和iOS的Flash Builder 4.5   我正在使用itemRenderer和   iconitemrenderer类来制作一个   我的应用程序的选项列表。

实际上,根据您在示例中显示的代码,您没有使用ItemRenderer类;只是IconItemRenderer课程。您看到的语法,如下所示:

         

是用于在MXML中将组件的属性定义为子项的语法。它引用List组件的itemRenderer属性;它没有引用ItemRenderer类。

也就是说,错误似乎是您尝试引用字符串clickfn="Projects",就像它是一个类一样。因此,您会收到类型转换错误。如果指定完整的类路径,则可能会有更好的运气。

此外,您的三个项目没有定义clickFn;所以他们可能会抛出类似的错误。

答案 1 :(得分:1)

您可以通过执行以下操作来简化JacobL答案中的变更处理程序逻辑:

<s:List id="list1" height="100%" width="100%" change="navigator.pushView(list1.selectedItem.nextView)">
    <s:itemRenderer>
        <fx:Component>
            <s:IconItemRenderer labelField="name"/>
        </fx:Component>
    </s:itemRenderer>
    <s:dataProvider>
        <s:ArrayList>
            <s:DataItem name="Projects" message="Learn more about what we're working on" nextView="{views.Projects}" />
            <s:DataItem name="Locate Office" message="Find directions to our nearest office" nextView="{views.Locate}" />
            <s:DataItem name="Contact Us" message="Let us know your thoughts!" nextView="{views.ContactUs}" />
            <s:DataItem name="About Us" message="" nextView="{views.AboutUs}" />
        </s:ArrayList>
    </s:dataProvider>
</s:List>

答案 2 :(得分:1)

你可以通过上面的建议来获得条件:

<pre>
<s:dataProvider>
<s:ArrayList>
    <s:DataItem name="Projects" message="Learn more about what we're working on"   nextView="{views.Projects}" />
    <s:DataItem name="Locate Office" message="Find directions to our nearest office" nextView="{views.Locate}" />
    <s:DataItem name="Contact Us" message="Let us know your thoughts!" nextView="{views.ContactUs}" />
    <s:DataItem name="About Us" message="" nextView="{views.AboutUs}" />
    </s:ArrayList></s:dataProvider>

<s:change>
navigator.pushView(event.currentTarget.selectedItem.nextView);
</s:change>

答案 3 :(得分:0)

想出来。这是一个解决方案:

<s:List height="100%" width="100%">
    <s:itemRenderer>
        <fx:Component>
            <s:IconItemRenderer height="100" labelField="name" 
                                iconField="photo" iconHeight="80" 
                                iconWidth="80" messageFunction="getMessage">
                <fx:Script>
                    <![CDATA[
                        import spark.components.NavigatorContent;
                        protected function getMessage(o:Object):String
                        {
                            return o.message;
                        }
                    ]]>
                </fx:Script>
            </s:IconItemRenderer>
        </fx:Component>
    </s:itemRenderer>
    <s:dataProvider>
        <s:ArrayCollection>
            <fx:Object name="Projects" photo="@Embed('libs/ProjectsIcon2.png')" message="Learn more about what we're working on">
            </fx:Object>
            <fx:Object name="Locate Office" photo="@Embed('libs/google-maps-icon.png')" message="Find directions to our nearest office">
            </fx:Object>
            <fx:Object name="Contact Us" photo="@Embed('libs/gmailicon.png')" message="Let us know your thoughts!">
            </fx:Object>
            <fx:Object name="About Us" photo="@Embed('libs/info-icon.png')" message="">
            </fx:Object>
        </s:ArrayCollection>
    </s:dataProvider>
    <s:change>
              //these if statements were the solution i used. rough, but works well
        <![CDATA[
            if(event.currentTarget.selectedItem.name == "Projects"){navigator.pushView(Projects);}
        if(event.currentTarget.selectedItem.name == "Locate Office"){navigator.pushView(Locations);}
        if(event.currentTarget.selectedItem.name == "Contact Us"){navigator.pushView(Contact);}
        if(event.currentTarget.selectedItem.name == "About Us"){navigator.pushView(About);}
        ]]>
    </s:change>
</s:List>