【问题标题】:pass extra variable in an itemRenderer在 itemRenderer 中传递额外的变量
【发布时间】:2011-12-12 15:02:06
【问题描述】:

我有一个列表,它使用一个 arrayCollection 作为数据提供者和一个 itemRenderer 来显示一些东西,但是我怎样才能将一个额外的变量传递给这个 itemRenderer? 有什么帮助吗?

例如这里: adobe flex examples 如果我想传递一个额外的变量来声明可以找到图像的文件夹名称是什么?

先谢谢了!

【问题讨论】:

    标签: variables actionscript flex4 itemrenderer


    【解决方案1】:

    使用类工厂:

    [Bindable]
    protected var cf:ClassFactory;//bind your List's itemRenderer property to this
    
    protected function onPreInitialize():void {
       cf = new ClassFactory(YourRenderer);
       //note that {folder='theFolder'} is now {folder:'theFolder'}
       cf.properties = {folder:'theFolder'};//note that your renderer will need to expose a public folder property
    }
    

    【讨论】:

    • 我按照你说的做了以下操作:[Bindable]protected var cf:ClassFactory; protected function onPreInitialize():void { cf = new ClassFactory(VideoItemRenderer); cf.properties = {folder='images'}; } 但它给了我一个语法错误,我在我的 VideoItemRenderer 中输入了“public var folder:String;”可以吗,我必须在哪里调用 onPreInitialize() 函数?
    • 什么是语法错误?您要么需要使文件夹变量可绑定并绑定到它,要么使用 getter/setter 对值执行某些操作。在您的根 mxml 标记中,设置 preinitialize="onPreOnitialized"。
    • 在赋值之前期望冒号,在右括号之前期望标识符:cf.properties = {folder='images'};我也把这个 在我的 itemrenderer 中,并且在调用 itemrenderer 的组件中进行预初始化是否可以?
    • 我执行以下操作:我的组件和 i 组件中的 [Bindable]protected var cf:ClassFactory; protected function onPreInitialize():void { cf = new ClassFactory(VideoItemRenderer); cf.properties = {folder : 'images'}; } 以及我的 itemRenderer 中的 <fx:Script> <![CDATA[ import mx.controls.Alert; [Bindable]public var folder:String; public function onCreation():void { Alert.show(folder); } ]]> </fx:Script> bt 文件夹变量似乎在警报中没有价值...知道吗?跨度>
    • 另外我在我的 itemRenderer 中有这个来显示图像:<s:Image left="0" right="0" top="44" bottom="0" scaleMode="stretch" smooth="false" source="{folder}/{data.thumb}"/>
    猜你喜欢
    • 2015-09-15
    • 2011-11-03
    • 1970-01-01
    • 2012-02-15
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 2020-04-22
    相关资源
    最近更新 更多