Apache – How to cast one Flex object as a derived type

apache-flex

Here's the example:

var cartesian:CartesianChart = new CartesianChart(); 
cartesian.width = 100;
var column:ColumnChart = new ColumnChart();
column = cartesian as ColumnChart;

Why does this not work? "column" ends up null. ColumnChart is a derived class of CartesianChart, so I would have thought I'd end up with a ColumnChart with a width of 100.

Best Answer

ColumnChart extends CartesianChart? I don't believe you can cast an object from a parent class to an object of it's child class. Your best bet is to write a class function on ColumnChart called something like copyFromCartesianChart that takes the CartesianChart object as a param and gets and sets all the props you need.

Related Topic