【问题标题】:Flex/Flash Builder: Embedding the same asset in multiple componentsFlex/Flash Builder:在多个组件中嵌入相同的资源
【发布时间】:2012-01-26 13:36:26
【问题描述】:

如果我在 Flex 应用程序的多个组件中嵌入了相同的资产(即图像或声音文件),编译后的 swf 是否只包含一次资产(及其文件大小),还是每次嵌入时只包含一次?

【问题讨论】:

    标签: apache-flex flash-builder embed


    【解决方案1】:

    多次嵌入相同的资产将使您的 swf 更高。 No of times x Assest 不会花费应用程序文件大小的一倍。例如,如果您两次使用相同的资产,则编译后的 swf 将是单次嵌入的两倍。

    我尝试如下

    我的代码如下

    <fx:Script>
        <![CDATA[
            [Embed(source="CD2_AUDIO.mp3")]
            [Bindable]
            public var sndCls:Class;
    
            [Embed(source="CD2_AUDIO.mp3")]
            [Bindable]
            public var sndCls2:Class;
    
            public var snd:Sound = new sndCls() as Sound; 
            public var sndChannel:SoundChannel;
    
            public function playSound():void {
                sndChannel=snd.play();
            }   
    
            public function stopSound():void {
                sndChannel.stop();
            }   
        ]]>
    </fx:Script>
    
    <mx:HBox>
        <mx:Button label="play" click="playSound();"/>
        <mx:Button label="stop" click="stopSound();"/>
    </mx:HBox>
    

    注意:音频大小为 26 MB

    构建后我去 bin-debug 并注意到应用程序的文件大小约为 57,004,925 字节,因为我使用了两次。

    当我只使用一次资产时,它显示 28,817,403 字节。

    因此应用程序会增加您使用的次数。

                              ~~~~~Happy Coding~~~~~
    

    【讨论】:

    • 'Merged into code' 和 'RSL' 定义 Flex 框架和/或其他外部库如何链接到您的应用程序。我看不出这与这个问题有什么关系。
    • @RIAstar 感谢您在此处指定。我通过合并其他一些内容犯了错误。我修改了答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 2013-01-01
    相关资源
    最近更新 更多