Question

Je suis en train de détecter le chevauchement entre les éléments sur ma toile. La tentative est de réutiliser une partie du code pour la détection de collision à http://www.gskinner.com/blog/archives/2005/ 08 / flash_8_shape_b.html

Ceci est le plus petit échantillon MXML je pouvais venir avec cela me donne une erreur de type.

    <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>

L'exécution de ce code échoue avec

Main Thread (Suspended: TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Bitmap@3b81971 to mx.core.IUIComponent.) 

mx.core :: Container / http: //www.adobe .com / 2006 / flex / mx / interne :: addingChild  mx.core :: Container / addChildAt  mx.core :: Container / addChild  scratch / init  zéro / ___ scratch_Application1_creationComplete  flash.events::EventDispatcher/dispatchEventFunction [aucune source]  flash.events::EventDispatcher/dispatchEvent [aucune source]  mx.core :: UIComponent / dispatchEvent  mx.core :: UIComponent / set initialisé  mx.managers :: LayoutManager / doPhasedInstantiation  mx.managers :: LayoutManager / doPhasedInstantiationCallback

Quelqu'un peut-il voir ce que je suis absent? Merci à l'avance pour toute aide. -v

Était-ce utile?

La solution

Vous essayez d'ajouter un BitMap comme un enfant sur une toile. La méthode addChild accepte un DisplayObject , que le bitmapData n'est pas.

Vous pouvez probablement régler le Bitmap à la balise la source d'un image et ajouter que comme un enfant. Bien que je ne suis pas spécialement sûr pourquoi vous ne recevez pas une erreur sur la conversion pour Bitmap à DisplayObject par opposition à UIComponent.

Sur une note sans rapport avec le fait que vous avez « ceci est un test » sous forme de texte dans l'étiquette me semble erroné; Flex 4 ne savoir quoi faire avec cela?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top