【问题标题】:spark List with ItemRenderer click function not working带有ItemRenderer单击功能的火花列表不起作用
【发布时间】:2011-02-09 15:55:59
【问题描述】:

我的 ItemRenderer 出现问题,我将其用于 spark 列表。我的代码如下:

我有这个清单:

<s:List 
    id="productSetList" 
    dataProvider="{ model.productSets }" 
    change="model.selectSet( productSetList )" 
    height="100%" width="100%"
    borderVisible="false" 
    itemRenderer="SideBarItemRenderer" top="20" left="15">
</s:List>

而我的 itemRenderer 是:

<s:ItemRenderer 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/halo" 
    width="160" height="175" autoDrawBackground="false" buttonMode="true" useHandCursor="true"
    click="click(event)" cacheAsBitmap="true"
    >


    <fx:Script>
        <![CDATA[
            import com.png.vm.model.vos.ProductSet;

            protected function click(event:MouseEvent):void
            {
                trace('arthur');
            }

        ]]>
    </fx:Script>

    <s:BitmapImage source="{ProductSet(data).image}" width="160" height="175"/>

</s:ItemRenderer>

问题是,如果我滚动列表并单击一个项目,它不会跟踪“亚瑟”!为什么会这样?我必须跟踪有人在列表中单击的所有时间!

编辑: 如果我删除列表中的change="model.selectSet( productSetList )",它会起作用!!但我不能删除它,一些建议?如何将其切换到另一个功能?

【问题讨论】:

  • 你在调试/使用调试版的Flash Player吗?
  • 试着把它放在大括号里:change="{model.selectSet( productSetList )}".

标签: apache-flex actionscript-3 air flex4


【解决方案1】:

Trace 仅在您调试/使用 Flash Player 的调试版本时有效。确保你正在使用它。如果您想要弹出消息,请使用Alert.show("message")

有关 trace() 的更多信息,请查看: http://livedocs.adobe.com/flex/3/html/help.html?content=logging_08.html

还有 Alert.show():http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001965.html


如果您正在运行调试播放器。尝试从嵌入的&lt;s:Group&gt; 发起点击事件,这样无论您在位图之外添加什么,仍会触发点击事件。

类似:

<s:Group width="100%" height="100%" click="click(event)" >
    <s:BitmapImage source="{ProductSet(data).image}" width="160" height="175"/>
</s:Group>

我之前在 ItemRenderers 中肯定有点击事件为我工作

【讨论】:

  • 谢谢伊恩,但我一直没有联系到我m running as debug mode, all the other traces are working fine, the problem is that this function its!
  • 嗯。我肯定有在项目渲染中工作的点击事件。我将用另一个解决方案更新我的答案
【解决方案2】:

对不起,我终于解决了。问题是在函数内部,model.selectSet,我正在调用 List.change;我把名单搞砸了!我的功能如下:

    public function selectSet(list:List):void {
        list.layout.verticalScrollPosition=100;
        // another stuffs

    }

所以,我刚刚删除了这行:list.layout.verticalScrollPosition=100;,现在它可以正常工作了。

感谢大家的帮助!

【讨论】:

  • 为什么要从模型内部引用/调整视图?您的抽象正在泄漏...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-08
  • 1970-01-01
  • 1970-01-01
  • 2015-11-03
相关资源
最近更新 更多