Actionscript 3 AS3 FlashCS6位图数据向量

Actionscript 3 AS3 FlashCS6位图数据向量,actionscript-3,Actionscript 3,我想把所有的东西都制作成精灵,因为我听说这是个好主意,直到它不是专业动画。我是这样做的: //资产负债表 [Embed(source = "../lib/Textures/Game/GameBackground.jpg")] public static const GameBackground:Class; 当我想用这个的时候,我就有课了: //Game.as private var pic:Bitmap = new Assets.GameBackground(); private var D

我想把所有的东西都制作成精灵,因为我听说这是个好主意,直到它不是专业动画。我是这样做的:

//资产负债表

[Embed(source = "../lib/Textures/Game/GameBackground.jpg")] public static const GameBackground:Class;
当我想用这个的时候,我就有课了:

//Game.as

private var pic:Bitmap = new Assets.GameBackground();
private var DATA:Vector.<BitmapData> = new Vector.<BitmapData>([pic.bitmapData]);
private var backgroundImg:Bitmap = new Bitmap(new BitmapData(1, 1));    

public function Game(){
    addChild(backgroundImg);
    backgroundImg.bitmapData = DATA[0];
}
private-var-pic:Bitmap=new-Assets.GameBackground();
专用var数据:向量=新向量([pic.bitmapData]);
private-var-backgroundImg:Bitmap=new-Bitmap(new-BitmapData(1,1));
公共功能游戏(){
addChild(backgroundImg);
backgroundImg.bitmapData=数据[0];
}
我知道当我只有一个位图可以使用vector时,它是没有用的,但以后会有两个位图的精灵表或按钮。更重要的是,我想把这些向量存储在Asstets.as中 即使尝试在我希望使用的类中创建它们也有问题,因为:

  • 尝试:这样:
    data:Vector.=新向量([pic])
    接收错误:索引0超出范围0

  • 尝试:这样:
    data:Vector.=新载体[pic]
    接收:尝试在非构造函数上实例化。我想这很明显


  • 当我只使用
    pic:Bitmap
    backgroundImg.bitmapData=pic.bitmapData
    时,它可以工作,但我不希望这样。当一个精灵有很多位图时,需要使用矢量。甚至是一个世界。此外,希望在Assets.as类中创建这些向量。

    创建新的向量实例时,它接受的唯一参数(可选)是向量的长度(将有多少个元素)

    新向量:(5)
    
    这将告诉向量它将有5个元素。与数组不同,您不能在构造函数中传入元素。如果省略该参数,则会使长度动态,以便可以根据需要进行增长/收缩

    您需要执行以下操作:

    data:Vector.<BitmapData> = new Vector:<BitmapData>();
    data.push(pic.bitmapData);
    
    data:Vector.=新向量:();
    数据推送(pic.bitmapData);
    
    更多关于创建向量的信息

    当您创建一个新的Vector实例时,它接受的唯一参数(可选)是Vector的长度(您将拥有多少个元素)

    新向量:(5)
    
    这将告诉向量它将有5个元素。与数组不同,您不能在构造函数中传入元素。如果省略该参数,则会使长度动态,以便可以根据需要进行增长/收缩

    您需要执行以下操作:

    data:Vector.<BitmapData> = new Vector:<BitmapData>();
    data.push(pic.bitmapData);
    
    data:Vector.=新向量:();
    数据推送(pic.bitmapData);
    
    更多关于创建向量的信息

    你的想法很管用

    我为一些全球图像做了这项工作,效果非常好:

    [Embed(source="greenled.png")] private static const greenled:Class;
    [Embed(source="yellowled.png")] private static const yellowled:Class;
    [Embed(source="redled.png")] private static const redled:Class;
    public static const SIGN:Vector.<Class> = Vector.<Class>([greenled,yellowled,redled]);
    
    [Embed(source=“greenled.png”)]私有静态常量greenled:Class;
    [Embed(source=“yellowled.png”)]私有静态常量yellowled:Class;
    [Embed(source=“redled.png”)]私有静态常量redled:Class;
    公共静态常量符号:矢量向量([绿色、黄色、红色]);
    
    你的想法很管用=O

    我为一些全球图像做了这项工作,效果非常好:

    [Embed(source="greenled.png")] private static const greenled:Class;
    [Embed(source="yellowled.png")] private static const yellowled:Class;
    [Embed(source="redled.png")] private static const redled:Class;
    public static const SIGN:Vector.<Class> = Vector.<Class>([greenled,yellowled,redled]);
    
    [Embed(source=“greenled.png”)]私有静态常量greenled:Class;
    [Embed(source=“yellowled.png”)]私有静态常量yellowled:Class;
    [Embed(source=“redled.png”)]私有静态常量redled:Class;
    公共静态常量符号:矢量向量([绿色、黄色、红色]);