在项目渲染器中运行时创建自定义组件
我正在尝试对我的网站中的页面使用 coverflow 布局,即列表中的每个项目不是图像或面板,而是整个页面本身。这些页面本质上是自定义组件。
我想要的是能够在运行时在 ItemRenderer 中创建自定义组件的实例。例如,这是用于显示 coverflow 布局的代码:
<s:List id="pageList" depth="0" itemRenderer="com.helpdesk.proj.renderers.pageRenderer"
dataProvider="{menuItems}" selectedIndex="{navigationButtonGroup.selectedIndex}" borderVisible="false"
x="5" y="200" width="100%" height="500">
<s:layout>
<layouts:CoverFlowLayout id="hdCoverflow"
horizontalDistance="85"
selectedItemProximity="50"
selectedIndex="{pageList.selectedIndex}"
depthDistance="1"
elementRotation="-70"
focalLength="300"
perspectiveProjectionX="-1"
perspectiveProjectionY="-1"/>
</s:layout>
</s:List>
列表的数据提供者基本上是一个对象数组,其中包含顶部导航栏的名称(字符串)(主页、关于、联系我们等)。我创建了具有相同名称的自定义组件。即我有一个名为“home”、“about”等的自定义组件。
因此,在项目渲染器中,我想创建适当的自定义组件的实例。到目前为止,这就是我所拥有的:
<?xml version="1.0" encoding="utf-8"?>
import mx.core.UIComponent;
import mx.events.FlexEvent;
[Bindable]private var currItem:String = data.name;
protected function itemrenderer1_creationCompleteHandler(event:FlexEvent):void
{
var myClass:Class = Class(getDefinitionByName(currItem));
var mycomp:Object = new myClass();
}
]]>
</fx:Script>
我希望“mycomp”将保存当前自定义组件的实例。如何将此对象添加到应用程序中? 我尝试了parentDocument.addChild,但它引发了错误。还有其他方法可以完成整个事情吗?
I am trying to use the coverflow layout for the pages in my website i.e, each item in the list is not an image or panel, but an entire page itself. The pages are essentially custom components.
What I want is to be able to create instances of my custom component at runtime within my ItemRenderer. For example, this is the code for displaying the coverflow layout :
<s:List id="pageList" depth="0" itemRenderer="com.helpdesk.proj.renderers.pageRenderer"
dataProvider="{menuItems}" selectedIndex="{navigationButtonGroup.selectedIndex}" borderVisible="false"
x="5" y="200" width="100%" height="500">
<s:layout>
<layouts:CoverFlowLayout id="hdCoverflow"
horizontalDistance="85"
selectedItemProximity="50"
selectedIndex="{pageList.selectedIndex}"
depthDistance="1"
elementRotation="-70"
focalLength="300"
perspectiveProjectionX="-1"
perspectiveProjectionY="-1"/>
</s:layout>
</s:List>
The data provider for the list, is basically an array of objects which contains the name (string) of the top navigation bar (home, about, contact us etc). I have created custom components with the same names.i.e I have a custom component named "home","about" and so on.
So in the item renderer I want to create instance of the appropriate custom component. So far this is what I have :
<?xml version="1.0" encoding="utf-8"?>
import mx.core.UIComponent;
import mx.events.FlexEvent;
[Bindable]private var currItem:String = data.name;
protected function itemrenderer1_creationCompleteHandler(event:FlexEvent):void
{
var myClass:Class = Class(getDefinitionByName(currItem));
var mycomp:Object = new myClass();
}
]]>
</fx:Script>
I am hoping "mycomp" will hold an instance of the current custom component. How do I add this object to the application?
I tried parentDocument.addChild but it throws an error. Is there any other way of doing the whole thing ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this :