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开发者_Go百科 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?
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
精彩评论