在一个Flex Container中添加Sprite 对象

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

比如如下代码:

<mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <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属性

   public function ShowIt(e:Event):void
   {
    var bg:FlexSprite=new FlexSprite();
    canvas.rawChildren.addChild(bg);
    }

posted on 2010-08-16 10:28  jiahuafu  阅读(302)  评论(0编辑  收藏  举报

导航