Flex 在新面板中调用 ItemRenderer()
我有下面的函数在我的 ViewStack 中创建新面板。这工作正常,而且很棒。但是我试图将一些内容放入面板中,但我失败了。
private function viewstack_addChild(name:String):void {
//if (accordion.numChildren < MAX_CHILDREN) {
var p:Panel = new Panel();
p.id = name;
p.name = name;
p.title = name;
p.percentWidth = 100;
p.percentHeight = 100;
var display:PageItemRenderer = new PageItemRenderer;
p.finishPrint(display);
var randColor:uint = Math.random() * 0xFFFFFF;
p.setStyle("backgroundColor", randColor);
myViewStack.addChild(p);
//myViewStack.selectedChild = p;
//}
}
我有一个名为 PageItemRenderer 的自定义项目渲染器,它将接受 xml 数据并显示它,但我无法弄清楚如何为每个面板调用渲染器。
任何帮助将不胜感激。
编辑:添加 PageItemRenderer.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox
height="100%"
width="100%"
xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:HBox width="100%" height="100%">
<mx:VBox height="100%" width="20%" horizontalAlign="center" verticalAlign="middle">
<!-- software image -->
<mx:Image source="{data.image}" width="90%" height="90%"/>
</mx:VBox>
<!-- person's name -->
<mx:VBox height="100%" width="80%" horizontalAlign="left" verticalAlign="middle">
<mx:Label width="100%" height="100%" text="{data.name} {data.version}" color="#FFAE00"/>
<mx:Label width="100%" height="100%" text="{data.description}" color="#FFFFFF"/>
</mx:VBox>
</mx:HBox>
</mx:HBox>
I have the below function creating new panels inside my ViewStack.. This works fine and they are great.. However i am trying to put some content into the panels but i am failing.
private function viewstack_addChild(name:String):void {
//if (accordion.numChildren < MAX_CHILDREN) {
var p:Panel = new Panel();
p.id = name;
p.name = name;
p.title = name;
p.percentWidth = 100;
p.percentHeight = 100;
var display:PageItemRenderer = new PageItemRenderer;
p.finishPrint(display);
var randColor:uint = Math.random() * 0xFFFFFF;
p.setStyle("backgroundColor", randColor);
myViewStack.addChild(p);
//myViewStack.selectedChild = p;
//}
}
I have a custom itemrenderer called PageItemRenderer that will accept the xml data and display it but i cannot figure out how to call the renderer for each panel..
Any help would be greatly appreciated.
EDIT: Adding PageItemRenderer.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox
height="100%"
width="100%"
xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:HBox width="100%" height="100%">
<mx:VBox height="100%" width="20%" horizontalAlign="center" verticalAlign="middle">
<!-- software image -->
<mx:Image source="{data.image}" width="90%" height="90%"/>
</mx:VBox>
<!-- person's name -->
<mx:VBox height="100%" width="80%" horizontalAlign="left" verticalAlign="middle">
<mx:Label width="100%" height="100%" text="{data.name} {data.version}" color="#FFAE00"/>
<mx:Label width="100%" height="100%" text="{data.description}" color="#FFFFFF"/>
</mx:VBox>
</mx:HBox>
</mx:HBox>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Panel
只是一个容器类,您的PageItemRenderer
必须扩展一些UIComponent
,因此只需在您的viewstack_addChild
中执行此操作> 方法:编辑:将
pR.setData
更改为pR.data
编辑:将
pR.data(data)
更改为pR.data = data
;The
Panel
is just a container class, and yourPageItemRenderer
must extend someUIComponent
, so just do this in yourviewstack_addChild
method:EDIT: changed
pR.setData
topR.data
EDIT: changed
pR.data(data)
topR.data = data
;