我試圖檢測畫布上元素之間的重疊。 的嘗試是重用一些碰撞檢測的代碼在 http://www.gskinner.com/blog/archives/2005/08/flash_8_shape_b.htmlFlex/Actionscript類型錯誤#1034
這是最小的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::[email protected] to mx.core.IUIComponent.)
mx.core ::集裝箱/ http://www.adobe.com/2006/flex/mx/internal::addingChild mx.core ::集裝箱/ addChildAt mx.core ::集裝箱/的addChild 劃傷/初始化 scratch/___ scratch_Application1_creationComplete flash.events::EventDispatcher/dispatchEventFunction [no source] flash.events::EventDispatcher/dispatchEvent [no source] mx.core :: UIComponent/dispatchEvent mx.core :: UIComponent /套初始化 mx.managers ::佈局管理/ doPhasedInstantiation mx.managers ::佈局管理/ doPhasedInstantiationCallback
有人能看到我缺少的是什麼? 在此先感謝您的幫助。 -v