我正在尝试检测画布上元素之间的重叠。 尝试重用一些代码进行冲突检测 http://www.gskinner.com/blog/archives/2005/08/flash_8_shape_b.html
这是我能提出的最小的MXML样本,它给我一个类型错误。
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="init()">
<fx:Script>
<![CDATA[
public function init():void {
var matrix:Matrix = new Matrix();
var bounds:Rectangle = this.getBounds(this);
var img:BitmapData = new BitmapData(this.width, this.height);
img.draw(this,matrix,new ColorTransform(1,1,1,1,255,-255,-255,255));
var bm:Bitmap = new Bitmap(img);
bm.x = 0;
bm.y = 0;
canvas.addChild(bm);
}
]]>
</fx:Script>
<mx:Canvas id="canvas" width="600" height="600">
<s:Label id="text" x="100" y="100">
This is a test
</s:Label>
</mx:Canvas>
</s:Application>
运行此代码失败并显示
Main Thread (Suspended: TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Bitmap@3b81971 to mx.core.IUIComponent.)
mx.core ::集装箱/ http://www.adobe.com/2006/flex/mx/internal::addingChild mx.core ::集装箱/ addChildAt mx.core ::集装箱/的addChild 从头/ INIT 从头/ ___ scratch_Application1_creationComplete flash.events :::EventDispatcher / dispatchEventFunction [没有来源] flash.events :::EventDispatcher / dispatchEvent [没有来源] mx.core :: UIComponent / dispatchEvent mx.core :: UIComponent / set已初始化 mx.managers ::布局管理/ doPhasedInstantiation mx.managers :: LayoutManager / doPhasedInstantiationCallback
谁能看到我错过的东西? 在此先感谢您的帮助。 -v