在Flex的帮助文档里,有很多例子都是扩展Sprite类的。如果想把这些实例添加到你的s:Application中,如:addChild(DisplayObject ),肯定会出错。错误的大致意思是:flash.display::Sprite没有实现mx.core.IUIComponent接口。
    Sprite->DisplayObjectContainer ->InteractiveObject ->DisplayObject ->EventDispatcher ->Object
从Sprite的继承关系来看,它虽然是DIsplayObject但是它没有实现IUIComponent,不能直接添加到Flex组件里是当然的了。
    Flex文档上指出所有的可视化控件都继承自UIComponent 而它自己是实现了IUIComponent 接口的。UIComponent 允许添加Sprite和MovieClip。
经常使用到的做法是:
   var comp: UIComponent = new UIComponent();
   comp.addChild(sprite);
   cavas1.addChild(comp);
这样flash控件就能正常在flex组件里显示了。
举个例子我在as文件中这么写 main.as
 <span style="font-size: medium;">package components
{
import flash.display.*;
import flash.net.URLRequest;
public class Main extends Sprite {
public function Main( ) {
var loader:Loader = new Loader( );
addChild( loader );
loader.load( new URLRequest( "img/aa.jpg" ) );
}
} }</span>

然后具体显示就想上面说的那样:

 <span style="font-size: medium;"><?xml version="1.0" encoding="utf-8"?>
<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:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import components.Main; import mx.core.UIComponent;
function init():void{
var comp: UIComponent = new UIComponent();
var main:Main=new Main();
comp.addChild(main);
this.addElement(comp);
}
]]>
</fx:Script>
</s:Application>
</span>

最后结果如下:

图片显示出来了鸟~

flex——将Sprite控件添加到FLEX UI中的更多相关文章

  1. MFC中给控件添加变量,DoDataExchange中

    DoDataExchange函数其实是一项数据动态绑定技术.比如你在写动态按钮过程中须对按钮添加变量时,怎么添加?控件类已经写好了,其变量是已经固定的.你要添加新的变量就要用到DoDataExchan ...

  2. asp.net中的ListBox控件添加双击事件

    问题:在Aspx页里的ListBox A中添加双击事件,将选中项添加到另一个ListBox B中,双击ListBox B中的选中项,删除当前选中项 页面: <asp:ListBox ID=&qu ...

  3. 【C#】使用IExtenderProvider为控件添加扩展属性,像ToolTip那样

    申明: - 本文适用于WinForm开发 - 文中的“控件”一词是广义上的说法,泛指包括ToolStripItem.MenuItem在内单个界面元素,并不特指继承自Control类的狭义控件 用过To ...

  4. iOS 在xib或storyboard里为控件添加圆角、外框和外框颜色

    如果要在xib和storyboard里为控件添加圆角和外框宽度,只要这样做就可以 layer.borderWidth     设置外框宽度属性 layer.cornerRadius    设置圆角属性 ...

  5. MFC编程入门之九(对话框:为控件添加消息处理函数)

    这一节讲的主要内容是如何为控件添加消息处理函数. MFC为对话框和控件定义了诸多消息,我们对他们操作时会触发消息,这些消息最终由消息处理函数处理,比如我们点击按钮时就会产生BN_CLICKED消息,修 ...

  6. 如何给ActiveX控件添加“事件”“属性”“标准事件”“自定义事件”等一些相关操作

    上一篇小编带大家熟悉了一下ActiveX的建立以及相关的概念,(http://blog.csdn.net/u014028070/article/details/38424611) 本文介绍下如何给控件 ...

  7. repeater中后台动态为控件添加属性

    在此贴出repeater中的ItemDataBound事件中的代码: private void ItemDataBound(object sender, RepeaterItemEventArgs e ...

  8. iOS在xib或storyboard里为控件添加圆角、外框和外框颜色

    如果要在xib和storyboard里为控件添加圆角和外框宽度,只要这样做就可以: layer.borderWidth 设置外框宽度属性 layer.cornerRadius 设置圆角属性 只要为属性 ...

  9. 在C#中使用属性控件添加属性窗口

    转自原文 在C#中使用属性控件添加属性窗口 第一步,创建在应用程序中将要展现的字段属性为public公有属性.其中,所有的属性必须有get和set的方法(如果不设置get方法,则要显示的属性不会显示在 ...

随机推荐

  1. DDMS files not found:hprof-conv.exe的解决办法

    或者是you must restart adb and eclipse这类错误 原因:一般是豌豆荚之类的软件影响的,所以,以后要慎用了. 解决方案:先找一下在sdk\tools目录下是否有hprof- ...

  2. Installing — pylibmc 1.2.3 documentation

    Installing - pylibmc 1.2.3 documentation libmemcached

  3. javax.Swing 使用GridBagLayout的程序栗子

    摘自https://zhidao.baidu.com/question/110748776.html javax.Swing 使用GridBagLayout的程序栗子 总共两个文件,第一个是启动文件, ...

  4. poj 3301 Texas Trip(几何+三分)

    Description After a day trip with his friend Dick, Harry noticed a strange pattern of tiny holes in ...

  5. Struts2(一)——总体介绍

    这篇博客开始将总结一下有关框架的知识,在开发中合适的利用框架会使我们的开发效率大大提高.当今比较流行的开源框架: 关注数据流程的MVC框架 (Struts1/2, WebWork, Spring MV ...

  6. Bestcoder HDU5059 Help him 字符串处理

    Help him Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  7. background小结

    CSS背景属性Background详解 本文详解了CSS的背景属性Background,包括CSS3中新增的背景属性.如果你是个CSS初学者,还可以查看之前介绍的CSS浮动属性和CSS透明属性详解. ...

  8. Information seeking letter, hard copy version

    23 Roanoke Street Blacksburg, VA 24060 (540) 555-1123 K.Walker@vt.edu October 23, 20XY Mr. James G. ...

  9. dojo.create\dojo.place\dojo.empty\dojo.destroy\dojo.body

    1.dojo.create 1.create a node; 2.set attributes on it;  3.place it in the DOM. dojo.create(/*String| ...

  10. 微软ajax组件

    拖个listview 然后绑定数据源,对curd选项打勾,然后拖个scriptManager进来,在拉个updatepanel进来,在updatepanel中放入个contentTemplate,吧l ...