AS3 Embed

常用來與變數綁定圖片、swf等等..供其他部份使用,比如icon
Bindable也會用到[],主要是綁定數據用..
[swf(...)]設定主swf一些編譯的常數,比如背景色,高跟寬等等。
AS3 嵌入式Embed的用法

  以前只知道外部加载文件图片用load,今天发现一个新东西,记录下来以备查阅。外部加载可以用load和Embed方法,他们区别在于

Embed表示编译的时候加载而load表示执行时加载。Embed和load的用法差不多,如果要在编译时加载,用 [Embed

(source="picture.jpg")]
                      private var Image:Class;

  现在Image类就包含了外部的源,要调用是直接new就行了。注意!!在[Embed(source="picture.jpg")]
后面千万别加分号,否则会报错的哈。

例子:
而在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);   
        }     
    }   

使用Embed嵌入图片文件后..
我们一样可以使用img标签的src属性来指定嵌入的图片资源..
不过在指定的时候..需要以"所在类名_变量名"的形式来指定..
上例中:
所在类名为EmbedImageForTextField
变量名为yellow
那指定的时候就需要写为"EmbedImageForTextField_yellow";

 

package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.Bitmap;
public class App extends Sprite
{
[Embed(source="library.swf", symbol="star")]
private var Star:Class;
[Embed(source="library.swf", symbol="square")]
private var Square:Class;
[Embed(source="library.swf", symbol="circle")]
private var Circle:Class;
[Embed(source="picture.jpg")]
private var Picture:Class;
public function App()
{
init();
}
private function init():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
var star:Sprite = new Star();
addChild(star);
star.x = 100;
star.y = 100;
var square:Sprite = new Square();
addChild(square);
square.x = 200;
square.y = 100;
var circle:Sprite = new Circle();
addChild(circle);
circle.x = 300;
circle.y = 100;
var picture:Bitmap = new Picture();
addChild(picture);
picture.x = 400;
picture.y = 100;
}
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值