AS项目下使用TextField的IMG标签显示Embed的图片

By:L4cd Date:2009-06-06

在Flash IDE下..我们直接使用
txt.html = "这里显示一张库里的图片<img src='库id'/>";
即可把库里的图像显示到文本框内

而在AS工程下...我们一样可以做到这样的功能...



package {  
    import flash.display.Sprite;  
    import flash.text.*;  
      
    public class EmbedImageForTextField extends Sprite 
    {  
        [Embed(source="image.png")]  
        private var yellow:Class;  
        public function EmbedImageForTextField()  
        {  
            var t:TextField = new TextField();  
            t.htmlText = "这里显示一张库里的图片<img src='EmbedImageForTextField_yellow'/>";  
            addChild(t);  
        }     
    }  

package {
 import flash.display.Sprite;
 import flash.text.*;
 
 public class EmbedImageForTextField extends Sprite
 {
  [Embed(source="image.png")]
  private var yellow:Class;
  public function EmbedImageForTextField()
  {
   var t:TextField = new TextField();
   t.htmlText = "这里显示一张库里的图片<img src='EmbedImageForTextField_yellow'/>";
   addChild(t);
  }  
 }
}
使用Embed嵌入图片文件后..
我们一样可以使用img标签的src属性来指定嵌入的图片资源..
不过在指定的时候..需要以"所在类名_变量名"的形式来指定..
上例中:
所在类名为EmbedImageForTextField
变量名为yellow
那指定的时候就需要写为"EmbedImageForTextField_yellow";
 

参与讨论去: 艾睿(Airia) 交朋友去:友吧推荐文章去:网站贴吧
企业招聘

北京中视力天文化传媒有限公司

公司简介:北京中视力天文化传媒有限公司,是CCTV.com央视国际网络有限公司投资的互联网研发团队。我们是天使的使者。。。

招聘FlashAS程序员详情点击

Copyright 2007-2008 51AS.com Extended in kingcms 鲁ICP备06001158号