如何访问中的组件在 MXML 类中?
是否可以在 MXML 类中将声明的组件作为 IFactory 进行访问?我已经多次使用这种声明工厂的方式来声明皮肤部件,但我从未弄清楚如何从 MXML 中访问这些工厂。
下面是我期望的工作示例:
<fx:Declarations>
<fx:Component id="labelDisplay">
<s:Label fontSize="12" fontWeight="bold"/>
</fx:Component>
</fx:Declarations>
<fx:Script>
<![CDATA[
override protected function createChildren():void
{
super.createChildren();
var label1:Label = labelDisplay.newInstance();
addElement(label1);
var label2:Label = labelDisplay.newInstance();
addElement(label2);
var label3:Label = labelDisplay.newInstance();
addElement(label3);
}
]]>
</fx:Script>
* 编辑 *
我希望上述代码能够工作的原因是基于 Spark 蒙皮架构中处理动态蒙皮部件的方式。如果上面的代码是 MXML 外观类的一部分,那么在我的主机组件中,我可以有以下内容。
[SkinPart(required="true",type="spark.controls.Label")]
public var labelDisplay:IFactory;
在 Spark 换肤架构中,
Is it possible to access a declared component as an IFactory within an MXML class? I've used this style of declaring factories many times for Skin Parts, but I've never figured out how to access those factories from within the MXML.
Here's an example of what I would expect to work:
<fx:Declarations>
<fx:Component id="labelDisplay">
<s:Label fontSize="12" fontWeight="bold"/>
</fx:Component>
</fx:Declarations>
<fx:Script>
<![CDATA[
override protected function createChildren():void
{
super.createChildren();
var label1:Label = labelDisplay.newInstance();
addElement(label1);
var label2:Label = labelDisplay.newInstance();
addElement(label2);
var label3:Label = labelDisplay.newInstance();
addElement(label3);
}
]]>
</fx:Script>
* edit *
The reason I was hoping the above code would work is based on the way dynamic Skin Parts are handled in the Spark skinning architecture. If the above code were a part of an MXML skin class, then in my host component, I could have the following.
[SkinPart(required="true",type="spark.controls.Label")]
public var labelDisplay:IFactory;
In the Spark skinning architecture, at what point does the <fx:Component> turn into an IFactory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我深入研究了 Flex 的 SkinnableComponent,根据他们如何将 MXML Skin 绑定到 AS HostComponent 来找到解决方案。显然,即使“labelDisplay”没有作为具体类成员显示在 FlashBuilder 的自动完成中,您仍然可以将其作为动态属性引用。我在这里修改了原来的示例:
I dug into Flex's SkinnableComponent to find the solution based on how they tie an MXML Skin to an AS HostComponent. Apparently, even though "labelDisplay" doesn't show up in FlashBuilder's autocomplete as a concrete class member, you can still reference it as a dynamic property. I've modified my original example here:
我看到的问题是您没有创建 iFactory,因此无法访问 iFactory 方法。
如果您需要的话,我建议您使用 ActionScript 并实际创建一个 iFactory。这使用 ClassFactory 类
然后你的createChildren 代码应该按原样工作。
The problem I see is that you didn't create an iFactory, so won't be able to access iFactory methods.
I would recommend you drop into ActionScript and actually create an iFactory if you need one. This uses the ClassFactory class
Then your createChildren code should work as is.