【问题标题】:Storing files temporarily and loading them again in AS3 without Air在没有 Air 的情况下临时存储文件并在 AS3 中再次加载它们
【发布时间】:2011-12-15 23:12:26
【问题描述】:

我在我的 Flex 应用程序中从服务器加载文件(或者更确切地说是图片),从技术上讲是从数据库加载。我一次显示其中一些,将其视为图像预览,并且我经常再次显示相同的图像。但我不想一次又一次地重新下载相同的文件,所以我想将它存储在本地,如果可用则从那里加载(或在必要时下载)。如果文件可以存储在 AppData/iDontCare 中的某个临时文件夹中并在应用程序重新启动时被删除,我会非常高兴。

File.applicationStorageDirectory 符合要求,但仅存在于 Air 中。

我错过了什么?

【问题讨论】:

    标签: actionscript-3 apache-flex file caching temporary-files


    【解决方案1】:

    也许考虑将图像作为字节数组存储在共享对象中,这听起来不是最好的解决方案,但这是目前想到的 :)

    在这里阅读更多:Is it possible to store images in the SharedObject of Flash?

    除此之外,如果您不使用 AIR 或 3rd parth swf 包装器,我相信您会受到浏览器缓存的支配,除非我忘记了其他内容。

    【讨论】:

    • 无论如何,我都会将图片存储在二进制数组中。我知道这很笨拙而且很慢(而且我还没有弄清楚如何在 php/flex 中正确传输和转换它),但是如果它必须在某个时候进入 RDBMS,几乎没有更好的方法来做到这一点( 那个是不可协商的)。您链接的示例几乎就是我正在搜索的内容,如果没有更好的结果,我将尝试实现该示例。谢谢。
    【解决方案2】:

    为此重新发明轮子是没有意义的,只需使用正确的标头设置您的服务器响应,以便网络浏览器可以缓存它们。设置服务器端应该相当容易,并且需要 no 设置客户端,只需像第一次一样再次加载所有内容,它将神奇地来自缓存而不是服务器。

    关于缓存头配置,see this question 或简单地用谷歌搜索一下更适合您的特定情况的东西。

    【讨论】:

    • 让我指定:我目前正在请求图像作为 POST 的结果(尽管我想我可能可以为此使用 GET),其中有六个参数,其中一些是用户-related,其他指向图像的,等等。如何“轻松”设置我的 php/SQL,使其自动缓存?此外,两组不同的参数可能会导致获取同一张图片(但我可以在请求发生之前在客户端上解决这个问题),我想避免这种情况。
    • 我更新了一些关于在 php 中设置缓存头的信息,你根本不需要接触你的 sql。将需要执行 GET,但参数的数量并不重要,只要它们每次都相同并且删除任何“重复”也会有所帮助。
    • 这是一个更干净的 SharedObject 解决方案,+1UP
    【解决方案3】:

    也许,您可以在客户端尝试图像缓存。 示例:

    <s:Application 
        xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:mx="library://ns.adobe.com/flex/mx"
        xmlns:s="library://ns.adobe.com/flex/spark">
    
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
    
    <fx:Script>
    <![CDATA[
    private function setView(index:int):void
        {
            tn.selectedIndex = index;
    
            switch(index)
            {
                case 0: 
                    myCache.prioritize("Employees");
                    break;
                case 1: 
                    myCache.prioritize("Managers");
                    break;
                case 2: 
                    myCache.prioritize("Execs");
                    break;
            }
        }       
    ]]>
    </fx:Script>
    
    <s:HGroup>
        <s:Button label="Employees" click="setView(0);"/>
        <s:Button label="Managers" click="setView(1);"/>
        <s:Button label="Execs" click="setView(2);"/>
    </mx:HGroup>
    
    <mx:TabNavigator id="navigator" width="100%" height="100%">
        <s:NavigatorContent label="Employees">
            <s:VGroup>
                <s:BitmapImage source="imgs/BigImage01.jpg" 
                    contentLoaderGrouping="Employees" contentLoader="{myCache}"/>
                <s:BitmapImage source="imgs/BigImage02.jpg" 
                    contentLoaderGrouping="Employees" contentLoader="{myCache}"/>
                <s:BitmapImage source="imgs/BigImage03.jpg" 
                    contentLoaderGrouping="Employees" contentLoader="{myCache}"/>
                ...
            <s:/VGroup>
        </s:NavigatorContent>
    
        <s:NavigatorContent label="Managers">
            <s:VGroup>
                <s:BitmapImage source="imgs/BigImage06.jpg" 
                    contentLoaderGrouping="Managers" contentLoader="{myCache}"/>
                <s:BitmapImage source="imgs/BigImage07.jpg" 
                    contentLoaderGrouping="Managers" contentLoader="{myCache}"/>
                <s:BitmapImage source="imgs/BigImage08.jpg" 
                    contentLoaderGrouping="Managers" contentLoader="{myCache}"/>
                ...
            <s:/VGroup>
        </s:NavigatorContent>
    
        <s:NavigatorContent label="Execs">
            <s:VGroup>
                <s:BitmapImage source="imgs/BigImage11.jpg" 
                    contentLoaderGrouping="Execs" contentLoader="{myCache}"/>
                <s:BitmapImage source="imgs/BigImage12.jpg" 
                    contentLoaderGrouping="Execs" contentLoader="{myCache}"/>
                <s:BitmapImage source="imgs/BigImage13.jpg" 
                    contentLoaderGrouping="Execs" contentLoader="{myCache}"/>
                ...
            <s:/VGroup>
        </s:NavigatorContent>
    
    </mx:TabNavigator>
    
    
    <fx:Declarations>
        <s:ContentCache name="myCache" enableQueuing="true"/>
    </fx:Declarations>
    

    查看以下链接: http://opensource.adobe.com/wiki/display/flexsdk/Spark+Image

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-08
      • 2015-10-12
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多