Apache flex UIComponent基类不工作
我有一个BaseComponentClass,我使用它作为所有自定义组件扩展的类。 由于某些原因,我的自定义组件都不会在运行时显示。我也没有收到任何编译或运行时错误。 我正在实现所有受保护的UIComponent方法。 我的代码如下所示:Apache flex UIComponent基类不工作,apache-flex,actionscript-3,mxml,Apache Flex,Actionscript 3,Mxml,我有一个BaseComponentClass,我使用它作为所有自定义组件扩展的类。 由于某些原因,我的自定义组件都不会在运行时显示。我也没有收到任何编译或运行时错误。 我正在实现所有受保护的UIComponent方法。 我的代码如下所示: public class BaseComponentClass extends UIComponent { public function BaseComponentClass() { super(); } o
public class BaseComponentClass extends UIComponent
{
public function BaseComponentClass()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
override protected function createChildren():void
{
super.createChildren();
for (var i:uint=0; i < super.numChildren; i++)
{
var childObj:DisplayObject = super.getChildAt(i);
addChild(childObj);
}
}
override protected function commitProperties():void
{
super.commitProperties();
}
override protected function measure():void
{
super.measure();
}
}
<local:BaseComponentClass xmlns:local="local.com.*" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Button id="btn" label="My Button" />
</local:BaseComponentClass>
公共类BaseComponentClass扩展UIComponent
{
公共函数BaseComponentClass()
{
超级();
}
重写受保护的函数updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):无效
{
super.updateDisplayList(unscaledWidth、unscaledHeight);
}
重写受保护的函数createChildren():void
{
super.createChildren();
for(变量i:uint=0;i
然后,我将其用作mxml自定义组件中的基类,有点像这样:
public class BaseComponentClass extends UIComponent
{
public function BaseComponentClass()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
override protected function createChildren():void
{
super.createChildren();
for (var i:uint=0; i < super.numChildren; i++)
{
var childObj:DisplayObject = super.getChildAt(i);
addChild(childObj);
}
}
override protected function commitProperties():void
{
super.commitProperties();
}
override protected function measure():void
{
super.measure();
}
}
<local:BaseComponentClass xmlns:local="local.com.*" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Button id="btn" label="My Button" />
</local:BaseComponentClass>
该按钮在运行时从未出现。是否尝试为该组件设置宽度和高度 默认情况下,UIComponent的宽度和高度设置为0 您可以在此处查看默认值文档,并在基本组件上相应地进行更改:
祝你好运 您是否尝试为该组件设置宽度和高度 默认情况下,UIComponent的宽度和高度设置为0 您可以在此处查看默认值文档,并在基本组件上相应地进行更改:
祝你好运 我不确定最佳实践,所以在实现它之前一定要研究一下,但如果是我,我会创建一个数组属性(可以从uicomponent获得子级),然后在类中的某个地方使用defaultProperty元数据标记([defaultProperty(“children”)])
如果要调试代码并在for循环中设置断点,则永远不会碰到addChild代码。实际上,转到createChildren(uiComponent.createChildren)的定义(f3),您会发现它是空的。必须在创建的默认属性设置器中显式调用addChild。如果您总是将此组件用作类似容器的类,那么最好的选择是扩展容器。F3深入这些类以了解最佳实践。我不确定最佳实践,所以在实现它之前一定要研究一下,但如果是我,我会创建一个数组属性(可以从uicomponent获得子级),然后在类中的某个地方使用defaultProperty元数据标记([defaultProperty(“children”))
如果要调试代码并在for循环中设置断点,则永远不会碰到addChild代码。实际上,转到createChildren(uiComponent.createChildren)的定义(f3),您会发现它是空的。必须在创建的默认属性设置器中显式调用addChild。如果您总是将此组件用作类似容器的类,那么最好的选择是扩展容器。F3深入到这些类中,以了解最佳实践。显然,您希望将子对象添加到BaseComponent中
为什么不从支持此功能的类(如Box或Canvas)继承呢?显然,您希望将子对象添加到BaseComponent
为什么不从支持此功能的类(如Box或Canvas)继承呢?是。是的。宽度和高度在flex应用程序上生效,但没有显示按钮。是的。是的。宽度和高度在flex应用程序上生效,但没有显示任何按钮。如果您不覆盖受保护的方法(因为您当前没有在这些方法中执行任何额外的工作),会发生什么?什么都不会发生。我上面描述的问题仍然存在。如果您不重写受保护的方法(因为您目前没有在这些方法中做任何额外的工作),会发生什么?什么都不会发生。我上面描述的问题仍然存在。我也想过这样做,但我想知道,与使用UIComponent作为基础相比,这样做是否会使我的flex应用程序更重。为什么需要基础类?您的组件中哪些共享代码不是UI组件的一部分,并且上面没有显示?也许还有别的办法。否则,使用容器类作为基类只会给您带来已经具备功能的容器的所有好处,如自动布局等。我也想过这样做,但我想知道这样做是否会使我的flex应用程序比使用UIComponent作为基类更重。您为什么需要基类?您的组件中哪些共享代码不是UI组件的一部分,并且上面没有显示?也许还有别的办法。否则,使用容器类作为基类只会为您提供具有自动布局等功能的容器的所有好处。