Question

I have a class called JDChart, and a class called JDLine. Inside JDChart there is a method called addLine() that expects 1 parameter of type JDLine. This is all good. but I want to be able to put this in XML Like this:

<JDChart>
<JDLine/>
<JDLine/>
<JDLine/>
</JDChart>

And for each JDLine nested in a JDChart in the MXML, I want the addLine() method to be called on the JDChart with the respective JDLine passed.

Does what I want to do make since? I am not sure how to set this up? I am assuming I have to use meta tags on the JDChart class somewhere to tell the compiler to do this? Does anyone know?

Thanks!!

Was it helpful?

Solution

I believe when you add things in MXML like that it will just construct them and then call addChild().

You could have JDChart override addChild(), and check the type of what's being added. If it's a JDLine you can then pass it to your addLine() method before passing it along to super.addChild().

OTHER TIPS

If JDLine objects are going to be parented only by JDChart objects, use this.

In the added event handler of the JDLine class, add the following code:

public function onAdded(e:Event):void
{
  var chart:JDChart = this.parent as JDChart;
  if(!chart)
    throw new Error("Parent is not JDChart");
  chart.addLine(this);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top