Canvas.addChild() only accepts UIComponents?
On 11/12/2007, at 10:01 AM, Merrill, Jason wrote:
Can anyone see the error in this setup?
//drawTest.mxml file:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" applicationComplete="init()"
backgroundColor="0xFFFFFF">
<mx:Script>
<![CDATA[
import src.DrawBitmap;
private function init():void
{
var spiral:DrawBitmap = new DrawBitmap(myCanvas);
}
]]>
</mx:Script>
<mx:Canvas id="myCanvas" x="10" y="10" width="774" height="463"
borderColor="0xD4001A" borderStyle="solid"/>
</mx:Application>
// DrawBitmap.as class:
package src
{
import mx.containers.Canvas;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
public class DrawBitmap
{
private var _canvas:Canvas;
private var _bitmap:Bitmap;
private var _imgData:BitmapData;
public function DrawBitmap(canvas:Canvas):void
{
_canvas = canvas;
_imgData = new BitmapData(20, 20, false, 0xFF00FF00);
_imgData.fillRect(new Rectangle(5, 5, 10, 10), 0xFF0000FF);
_bitmap = new Bitmap(_imgData);
_canvas.addChild(_bitmap); //Produces error
}
}
}
At runtime, I get this error in the debugger:
TypeError: Error #1034: Type Coercion failed: cannot convert
flash.display::[EMAIL PROTECTED] to mx.core.IUIComponent.
at mx.core::Container/http://www.adobe.com/2006/flex/mx/
internal::addingChild()[C:\dev\GMC\sdk\frameworks\mx\core
\Container.as:3303]
Seems to appear on the last line of the DrawBitmap class when I do
_canvas.addChild(_bitmap). That seems legal to me - add a bitmap
display object to a canvas display object. No? What am I
missing? If that's not legal, then how to add my bitmap object to
the canvas?
Thanks,
Jason Merrill
Bank of America
L&LD GT&O
eTools & Multimedia Research & Development