as:list用のカスタムItemRendererを作成しました。これには、MovieClipを含むUIComponentのリストが含まれています。スクロールすると、親/ x / yプロパティは正しいのに、一部のアイテムが表示/レンダリングされません。これがリストのItemRendererのコードです。render()は、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を削除し、新しいものを配置します。それは機能しますが、スクロール中にいくつかのランダムなアイテムが表示されず、もう一度スクロールするとランダムに表示されます。
助けてください..ありがとう。