IconItemRenderer
을 확장하여 작업중인 프로젝트에 필요한 사용자 지정 항목 렌더러를 만들었습니다. 이제는 렌더러가 정상적으로 작동합니다. 단, icon
및 decorator
이상의 이미지를 추가하는 방법을 알아낼 수는 없습니다. 3 개의 추가 이미지를 추가해야하며 이미지를 파악할 수 없습니다. 나는 (렌더러가 완전히 AS3로 작성) 노력 해왔다 무엇IconItemRenderer에 이미지를 추가하는 방법은 무엇입니까?
는 :
지금까지 내가 말할 수있는override protected function createChildren():void {
super.createChildren();
this.downloadIcon = new BitmapImage();
this.downloadIcon.source = "assets/images/download-160.png";
var down:DisplayObject = this.downloadIcon.createDisplayObject();
this.addChild(down);
}
, 그 작동합니다. 해당 소스를 iconDisplay 소스로로드하면 잘로드되므로 소스가 아닙니다. 또한 내가 사용하는 소스 (또는 로컬 대 외부)와 상관 없습니다. 또한 IconItemRenderer 소스의 코드를 사용하지 않으려 고 시도했습니다.
private function assignDisplayObject(bitmapImage:BitmapImage):void
{
if (bitmapImage)
{
// try using this display object first
if (bitmapImage.setSharedDisplayObject(this))
{
bitmapImage.displayObjectSharingMode = DisplayObjectSharingMode.USES_SHARED_OBJECT;
}
else
{
// if we can't use this as the display object, then let's see if
// the icon already has and owns a display object
var ownsDisplayObject:Boolean = (bitmapImage.displayObjectSharingMode != DisplayObjectSharingMode.USES_SHARED_OBJECT);
// If the element doesn't have a DisplayObject or it doesn't own
// the DisplayObject it currently has, then create a new one
var displayObject:DisplayObject = bitmapImage.displayObject;
if (!ownsDisplayObject || !displayObject)
displayObject = bitmapImage.createDisplayObject();
// Add the display object as a child
// Check displayObject for null, some graphic elements
// may choose not to create a DisplayObject during this pass.
if (displayObject)
addChild(displayObject);
bitmapImage.displayObjectSharingMode = DisplayObjectSharingMode.OWNS_UNSHARED_OBJECT;
}
}
}
두 가지 방법 중 하나를 사용하여 아무것도 표시되지 않습니다. 누군가 내가 이것을 잘못하고 있다고 설명 할 수 있을까요?
이 전혀 도움이된다면 플렉스 4.10 및 AIR 3.8을 사용.
편집 : Reboog의 요청에 따라, 여기에 전체 아이템 렌더러를 뺀
public class VideoItemRenderer extends IconItemRenderer
{
private static const OUTER_PADDING:uint = 15;
private static const INNER_PADDING:uint = 10;
private var description:StyleableTextField;
private var progressBar:ProgressBar;
private var downloadContainer:Group;
private var deleteIcon:VideoDeleteIcon;
private var downloadIcon:Image;
public function VideoItemRenderer()
{
super();
this.addEventListener(FlexEvent.DATA_CHANGE, this.dataChangeHandler);
this.minHeight = 106;
this.iconFunction = this.iconSelectFunction;
this.iconHeight = 76;
this.iconWidth = 107;
}
private function iconSelectFunction(item:Object):Object {
return "assets/images/background-160.png";
}
override protected function createChildren():void {
super.createChildren();
this.labelDisplay.wordWrap = true;
this.labelDisplay.multiline = true;
this.description = StyleableTextField(createInFontContext(StyleableTextField));
this.description.styleName = this;
this.description.editable = false;
this.description.selectable = false;
this.description.multiline = true;
this.description.wordWrap = true;
this.description.setStyle("fontFamily", "josefin");
this.description.setStyle("fontWeight", "bold");
this.description.text = "Vestibulum id ligula porta felis euismod semper. Cras mattis consectetur purus sit amet.";
this.addChild(this.description);
this.deleteIcon = new VideoDeleteIcon();
this.deleteIcon.addEventListener(MouseEvent.CLICK, this.deleteClickHandler);
this.addChild(this.deleteIcon);
this.downloadContainer = new Group();
this.addChild(this.downloadContainer);
this.progressBar = new ProgressBar();
this.downloadContainer.addChild(this.progressBar);
this.downloadIcon = new Image();
this.downloadIcon.source = "assets/images/download-160.png";
this.downloadContainer.addChild(downloadIcon);
}
override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void {
unscaledWidth = Math.min(this.owner.width, unscaledWidth);
graphics.beginFill(0xffffff, .1);
graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
graphics.endFill();
opaqueBackground = null;
}
override protected function layoutContents(unscaledWidth:Number, unscaledHeight:Number):void {
unscaledWidth = Math.min(this.owner.width, unscaledWidth);
super.layoutContents(unscaledWidth, unscaledHeight);
if (this.iconDisplay) {
this.setElementSize(this.iconDisplay, 107, 76);
this.setElementPosition(this.iconDisplay, OUTER_PADDING, OUTER_PADDING);
this.setElementPosition(this.labelDisplay, this.iconDisplay.x + this.getElementPreferredWidth(this.iconDisplay) + INNER_PADDING, OUTER_PADDING);
this.setElementPosition(this.description, this.iconDisplay.x + this.getElementPreferredWidth(this.iconDisplay) + INNER_PADDING, this.labelDisplay.y + this.getElementPreferredHeight(this.labelDisplay) + INNER_PADDING);
}
else {
this.setElementPosition(this.labelDisplay, OUTER_PADDING, OUTER_PADDING);
this.setElementPosition(this.description, OUTER_PADDING, this.labelDisplay.y + this.getElementPreferredHeight(this.labelDisplay) + INNER_PADDING);
}
this.setElementSize(this.labelDisplay, unscaledWidth - this.labelDisplay.x - OUTER_PADDING, this.getElementPreferredHeight(this.labelDisplay));
this.setElementSize(this.description, unscaledWidth - this.description.x - OUTER_PADDING, this.getElementPreferredHeight(this.description));
this.setElementPosition(this.deleteIcon, unscaledWidth - this.getElementPreferredWidth(this.deleteIcon), 0);
var descriptionHeight:Number = this.description.y + this.getElementPreferredHeight(this.description);
var iconHeight:Number = this.iconDisplay ? this.iconDisplay.y + this.getElementPreferredHeight(this.iconDisplay) : 0;
//this.setElementSize(this.progressBar, this.description.width, 5);
this.progressBar.width = this.description.width;
this.setElementPosition(this.downloadContainer, 0,Math.max(descriptionHeight, iconHeight) + OUTER_PADDING);
this.setElementPosition(this.progressBar, this.description.x, (this.getElementPreferredHeight(this.downloadContainer) - this.getElementPreferredHeight(this.progressBar))/2);
var downloadHeight:Number = this.getElementPreferredHeight(this.downloadContainer) + this.downloadContainer.y;
this.height = downloadHeight + OUTER_PADDING;
}
private function dataChangeHandler(e:FlexEvent):void {
if (this.data) {
this.label = this.data.label.toUpperCase();
}
}
}
BitMapImage 대신 Image를 사용하지 않는 이유는 무엇입니까? BitMapImage 인스턴스가 렌더링되기 전에 createDisplayObject()를 사용하고 있다고 추측해야합니다. 그러므로 아무 것도 나타나지 않습니다. – JeffryHouser
@ Reboog711 이전에'Image'를 사용해 보았으므로 아무 것도 표시되지 않았기 때문에'BitmapImage'를 사용하고있었습니다. 나는'IconItemRenderer' 소스를 통해'iconDisplay'가 어떻게 렌더링되고 그 것을 모방하려고하는지 알아 냈습니다. 방금 이미지를 다시 시도했지만 여전히 표시되지 않습니다. 아직 렌더링되지 않은 이미지에 대한 요점은 정확할 수도 있지만 이미지에서 실패한 이유는 설명하지 않습니다. –
다음 이미지는 이미지가 다른 것의 아래에 표시된다는 것입니다. 본질적으로 완전히 숨겨졌다. 그러나, 나는 당신이 확실히 알기에 충분한 정보를 제공했다고 생각하지 않습니다. – JeffryHouser