在项目渲染器中运行时创建自定义组件

发布于 2024-10-17 12:51:56 字数 1800 浏览 4 评论 0原文

我正在尝试对我的网站中的页面使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少心凉 2024-10-24 12:51:56

试试这个:

override protected function commitProperties():void {
    super.commitProperties();
    addCustomecomponent();
}

public function addCustomcomponent():void{

var myClass:Class = Class(getDefinitionByName(currItem));
            var mycomp:Object = new myClass();
    addElement(mycomp);   // addChild if you are using flex 3.6 or below

}

Try this :

override protected function commitProperties():void {
    super.commitProperties();
    addCustomecomponent();
}

public function addCustomcomponent():void{

var myClass:Class = Class(getDefinitionByName(currItem));
            var mycomp:Object = new myClass();
    addElement(mycomp);   // addChild if you are using flex 3.6 or below

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文