2011-10-02 33 views

回答

1

嵌入圖像的優勢在於它包含在SWF文件中,並且可以在應用程序必須在運行時從遠程位置加載它時以更快的速度訪問它。但它也有缺點,即您的SWF文件比在運行時加載資源時大。

的嵌入過程非常簡單,只要按照遵循以下步驟:

  1. 複製圖像文件,其中「源」文件夾是你的應用程序中。 Flex 4將從那裏獲取這些文件。當然你可以定義子文件夾不要搞亂。

  2. 在你的班級定義像下面的例子 [Embed(source =「728x90a.jpg」)] public static const imgData1:Class;

    The 728x90a.jpg is the file name of the image (I didn't use sub folders here) 
    The imgData1 is the object where contains the data of the embedded image! 
    
  3. 在代碼

    某處,將數據加載到一個可視化部件,如波紋管 img1.source = imgData1的例子; img1是一個圖像組件。

    package 
    { 
        public class TestProjectAssets 
        { 
         [Embed(source="fonts/MySuperDuperFont.otf", 
          fontFamily="SuperDuperFont", 
          mimeType="application/x-font", 
          embedAsCFF="true")] 
         private const SuperDuperFont:Class; 
    
         [Embed(source="assets/mainMenu.png")] 
         public static const mainMenuImg:Class; 
        } 
    } 
    

如果您需要處理大量的資源,你可以按照以下三個步驟:如果您選擇的是涉及加載外部文件要知道,有些閃光不同的方法

Place them in an uncompressed zip archive 

Embed the zip file as binary data: 

[Embed(source = 'resources.zip', mimeType = 'application/octet-stream')] 

Access the resources using [FZip][1] 

遊戲網站要求他們託管的遊戲包含在一個swf文件中。