Ninja_Warrior
01-19-2009, 06:46 PM
HI All, I am trying to add a Bitmap object to a canvas , but during runtime I am receiving error ...
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Bitmap@1691581 to mx.core.IUIComponent.
at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\Container.as:3251]
at mx.core::Container/addChildAt()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\Container.as:2200]
at mx.core::Container/addChild()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\Container.as:2140]
at ImageManipulation/createAnotherImage()[E:\Projects\ImageM\src\ImageManipulation.mxml:13]
at ImageManipulation/__createBitmap_click()[E:\Projects\ImageM\src\ImageManipulation.mxml:23]
Can someone please explain why it is happening and what is the workaround ?
I am adding source below.............
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private function createAnotherImage(source:Image):void{
var data:BitmapData = Bitmap(source.content).bitmapData;
var bitmap:Bitmap = new Bitmap(data);
bitmap.x = 200;
bitmap.y = 200;
trace(bitmap);
addChild(bitmap);
}
]]>
</mx:Script>
<mx:Canvas x="37" y="37" width="728" height="551" backgroundColor="white" id="canvasImage" label="Manipulating Image">
<mx:Image x="100" y="100" width="402" height="302" id="myImage" scaleContent="true" autoLoad="true"
source="assets/1.jpg" />
<mx:Button x="533" y="28" label="create Bitmap" width="111" height="29" id="createBitmap" click="createAnotherImage(myImage)"/>
</mx:Canvas>
</mx:WindowedApplication>
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Bitmap@1691581 to mx.core.IUIComponent.
at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\Container.as:3251]
at mx.core::Container/addChildAt()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\Container.as:2200]
at mx.core::Container/addChild()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\ core\Container.as:2140]
at ImageManipulation/createAnotherImage()[E:\Projects\ImageM\src\ImageManipulation.mxml:13]
at ImageManipulation/__createBitmap_click()[E:\Projects\ImageM\src\ImageManipulation.mxml:23]
Can someone please explain why it is happening and what is the workaround ?
I am adding source below.............
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private function createAnotherImage(source:Image):void{
var data:BitmapData = Bitmap(source.content).bitmapData;
var bitmap:Bitmap = new Bitmap(data);
bitmap.x = 200;
bitmap.y = 200;
trace(bitmap);
addChild(bitmap);
}
]]>
</mx:Script>
<mx:Canvas x="37" y="37" width="728" height="551" backgroundColor="white" id="canvasImage" label="Manipulating Image">
<mx:Image x="100" y="100" width="402" height="302" id="myImage" scaleContent="true" autoLoad="true"
source="assets/1.jpg" />
<mx:Button x="533" y="28" label="create Bitmap" width="111" height="29" id="createBitmap" click="createAnotherImage(myImage)"/>
</mx:Canvas>
</mx:WindowedApplication>