天天看點

在一個Flex Container中添加Sprite 對象

在flex 中, 直接向一個container (如: Canvas Panel) 對象中添加 Sprite 是不行的.

比如如下代碼:

 <mx:Script>

  <![CDATA[

   import com.roguedevelopment.pulse.PulseEngine;

   import com.roguedevelopment.pulse.simple.SimpleParticles;

   import mx.core.FlexSprite;

   public function ShowIt(e:Event):void

   {

    var bg:FlexSprite=new FlexSprite();

    canvas.addChild(bg);

   }

  ]]>

 </mx:Script>

 <mx:Canvas x="35.5" y="20" width="377" height="289" id="canvas"> 

 <mx:Button x="10" y="20" label="Show!" id="btnShow" click="ShowIt(event)" width="65"/>

 </mx:Canvas>

</mx:Application>

會報類型錯誤

TypeError: Error #1034: Type Coercion failed: cannot convert mx.core::FlexSprite@40b5271 to mx.core.IUIComponent.

應該用rawChildren屬性

    canvas.rawChildren.addChild(bg);

    }

上一篇: html meta

繼續閱讀