我为 as:list 创建了一个自定义 ItemRenderer,它包含一个 UIComponent 列表,其中包含一个 MovieClip。当我滚动时,一些项目没有显示/渲染,尽管它们的 parent/x/y 属性是正确的。这是列表的 ItemRenderer 的代码。render() 在触发渲染事件时发生:
<?xml version="1.0" encoding="utf-8"?>
<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/mx"
autoDrawBackground="true" creationComplete="init();" render="render();">
<s:Label id="lbl" text="{data.getName()}" width = "{width}" fontSize="14"/>
<fx:Script>
<![CDATA[
import Types.ReversingMovieClip;
import mx.core.UIComponent;
private var exDisplay:DisplayObject;
private var inited:Boolean = false;
private var uic:UIComponent = new UIComponent();
public function init():void
{
// first item is firing creationComplete twice !
if (!inited)
{
exDisplay = data.getDisplay();
// Dangerous. if exDisplay has a different event of CLICK, it won't set it here.
// On the other hand.. this happens at the startup.. so.. what to do.
if (exDisplay is ReversingMovieClip && !exDisplay.hasEventListener(MouseEvent.CLICK))
exDisplay.addEventListener(MouseEvent.CLICK, playPauseClip);
inited = true;
addElement(uic);
}
}
public function render():void
{
if (exDisplay != null && exDisplay.parent == uic)
uic.removeChild(exDisplay);
exDisplay = data.getDisplay();
//if (exDisplay.width != width && exDisplay.height != width)
resizeDisplay();
uic.width = exDisplay.width;
uic.height = exDisplay.height;
uic.addChild(exDisplay);
//ReversingMovieClip.setPlayBySpeed(true);
//ReversingMovieClip.setSpeed(1);
}
private function resizeDisplay():void
{
if (exDisplay.width > exDisplay.height)
{
exDisplay.width = width;
exDisplay.scaleY = exDisplay.scaleX;
}
else
{
exDisplay.height = width;
exDisplay.scaleX = exDisplay.scaleY;
exDisplay.x = width / 2 - exDisplay.width / 2;
}
uic.y = 12;
/* trace("listw " + width + "\nexHeight " + exDisplay.height + "exWidth " +
exDisplay.width + "\nuicW " + uic.width + " " + uic.height); */
}
private function playPauseClip(e:Event):void
{
var mc:ReversingMovieClip = (e.currentTarget as ReversingMovieClip);
if (mc.isPlaying())
mc.stop();
else mc.play();
}
]]>
</fx:Script>
</s:ItemRenderer>
UIComponent 或返回 MovieClip 的 data.getDisplay() 的定位不是问题。我使用 removeChildAt 删除该项目使用的最后一个 MovieClip,并放入新的。它有效,只是滚动时不显示一些随机项目,然后当您再次滚动时确实会出现..随机。
请帮忙..谢谢。