自定义组件中的 flash builder addChild 方法错误
我正在尝试制作一个折叠列表,就像谷歌广告词中的列表一样。编译器告诉我 addChild 不是有效的方法。这是我的代码:
package comps
{
import spark.components.Button;
import spark.components.Group;
import spark.components.TextArea;
public class CollapsibleList extends Group
{
private var btn : Button = new Button();
private var list : TextArea = new TextArea();
public function CollapsibleList()
{
super();
this.btn.width = 100;
this.btn.height = 20;
this.btn.label = "My Button";
this.btn.top = 0;
this.btn.left = 0;
this.list.width = 100;
this.list.height = 200;
this.list.top = 20;
this.list.left = 0;
this.addChild(this.btn);
this.addChild(this.list);
}
}
}
我在 main.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"
xmlns:comps="comps.*"
minWidth="955" minHeight="600">
<comps:CollapsibleList/>
</s:Application>
我假设编译器没有对我撒谎,那么我如何让这些对象(子对象)出现?
I am attempting to make a collapsing list like the ones in google adwords. The compiler is telling me that addChild is not a valid method. Here is my code:
package comps
{
import spark.components.Button;
import spark.components.Group;
import spark.components.TextArea;
public class CollapsibleList extends Group
{
private var btn : Button = new Button();
private var list : TextArea = new TextArea();
public function CollapsibleList()
{
super();
this.btn.width = 100;
this.btn.height = 20;
this.btn.label = "My Button";
this.btn.top = 0;
this.btn.left = 0;
this.list.width = 100;
this.list.height = 200;
this.list.top = 20;
this.list.left = 0;
this.addChild(this.btn);
this.addChild(this.list);
}
}
}
I call it simply in main.mxml like so:
<?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"
xmlns:comps="comps.*"
minWidth="955" minHeight="600">
<comps:CollapsibleList/>
</s:Application>
Im assuimg the compiler isn't lying to me so how do I get those objects (children) to appear?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Spark(Flex 4 框架)中,他们已经抽象出了整个“addChild”事物,因为您不直接使用 DisplayList。相反,您必须“addElement()”到组中。
但是,如果我没记错的话,addElement 需要 IVisualElement 作为参数。基本上,如果您习惯直接使用旧的 AS3“addChild()”,那么您将面临一段学习曲线 - 回报是值得的,但可能很困难。
这是一篇博客文章,似乎很好地解释了它,我希望这有所帮助:http:// www.billdwhite.com/wordpress/?p=296
In Spark, the Flex 4 framework, they've sort of abstracted out the whole "addChild" thing because you're not working with the DisplayList directly. Instead, you have to "addElement()" to a group.
However, addElement requires as a parameter to be an IVisualElement, if I remember correctly. Basically, if you're used to straight old AS3 "addChild()" then you're going to be in for a bit of a learning curve - the payoff is worth it, but it can be difficult.
Here's a blog post that seems to tear into it pretty well, I hope this helps: http://www.billdwhite.com/wordpress/?p=296