如何在不使用this.parent的情况下从Papervision类中以编程方式添加flex组件?

Rya*_* R. 0 apache-flex actionscript actionscript-3 papervision3d flex4

我有一个flex应用程序和一个papervision BasicView.我想在papervision类中添加一个新的flex UIComponent(例如一个按钮).我在下面发布了完整的示例代码.它有效,但我希望能够在没有"(this.parent.parent as Group).addElement(button);"的情况下完成我的目标.线.

<!--Application MXML-->
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="50" minHeight="50"
        creationComplete="Init()" applicationComplete="Start()">
    <fx:Script>
        <![CDATA[
            import mx.core.UIComponent;
            import spark.components.Button;
            public var start:QuickStart;
            public function Init():void
            {
                start = new QuickStart();
                var uicomp:UIComponent = new UIComponent();
                addElement( uicomp );
                uicomp.addChild( start );
            }

            public function Start():void
            {
                start.GoTime();
            }
        ]]>
    </fx:Script>
</s:Application>


//QuickStart.as
package{
    import org.papervision3d.view.BasicView;
    public class QuickStart extends BasicView
    {
        public function QuickStart()
        {
            super(500, 500, true, true);
        }

        public function GoTime():void
        {
            var button:Button = new Button;

            //this is the offending line
            (this.parent.parent as Group).addElement(button);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的版本确实有效,请原谅任何小错字.

Kod*_*iak 5

从逻辑上讲,你会BasicView在你的主应用程序中发送一个事件,在你的主应用程序中监听它,并从那里创建按钮.在一个完美的OOP世界中,每个类都应该是一个黑盒子发送事件:)