11 Replies Latest reply on Dec 28, 2006 8:30 AM by shoehn2

    AddChild(Sprite) to an mxml component

    mserranom
      Hi list! i'm porting an UML app from Aswing to Flex2, and i have a problem adding an sprite to a mx:Canvas (or other) mx component. for example, somethig like this:


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Canvas borderStyle="solid" height="200" width="80%" creationComplete="funcion()">
      <mx:Script>
      <![CDATA[
      private var size:uint = 80;
      private var bgColor:uint = 0xFFCC00;
      private var borderColor:uint = 0x666666;
      private var borderSize:uint = 0;

      private function funcion():void{
      var child:Sprite = new Sprite();
      var halfSize:uint = Math.round(size/2);
      child.graphics.beginFill(bgColor);
      child.graphics.lineStyle(borderSize, borderColor);
      child.graphics.drawCircle(halfSize, halfSize, halfSize);
      child.graphics.endFill();
      addChild(child);
      }
      ]]>
      </mx:Script></mx:Canvas></mx:Application>

      TypeError: Error #1034: Error de conversión forzada: no se puede convertir flash.display::Sprite@3237871 en mx.core.IUIComponent. (It can't cast from flash.display::Sprite to mx.core::IUIComponent)

      At flex2 reference it is marked as addChild(DisplayObject ) in every mxml component, not IUIComponent at any point.

      I can't use swfloader because i need to control this sprite with many mxml forms. Any idea?

      thank you!