This code is blunderous, as it adds a class to an array and later tries to pull it and manipulate it as if it were an object.
private function fail(event:Event):void
{
var myObj:MyClass;
var a:ArrayCollection = new ArrayCollection();
var x:MyClass;
var y:MyClass;
myObj = new MyClass;
a.addItem(myObj);
a.addItem(MyClass); // !!BAD!!
x = a[0];
y = a[1];
}
When I did this accidentally, it took me forever to see what I had done wrong. Partly because the error message didn't tell me anything I could understand:
TypeError: Error #1034: Type Coercion failed: cannot convert com.ibm.ITest::MyClass$ to com.ibm.ITest.MyClass.
at ITest/fail()[C:\work_simple01\ITest\src\ITest.mxml:51]
at ITest/___ITest_Button5_click()[C:\work_simple01\ITest\src\ITest.mxml:61]
So my question is, why is the line marked !!BAD!! above even allowed? I would expect a compile time error here. Since it compiles, there must be some use for this that I am unaware of. What is it?