我正在使用数字图书申请。我利用SWF Loader加载从PDF创建的SWF页面。我使用textsnapsot在页面上绘制内联文本突出显示。在整个会话中,突出显示在各个页面上彻底保留,稍后可以在没有任何问题的情况下更新/删除。一切正常工作,直到我在SWF加载方法中进行了以下更改来启用页面缓存:

我现在将SWF加载器对象加载到应用程序内存中,同时从一个页面跳转到其他页面,我只是将下一页的内容复制到显示给用户上的显示器上的当前SWF加载器。有两套SWF加载器 - 一个用于显示页面和其他用于缓存下一个/上一页的页面。在缓存方面,我将SWF加载到应用程序内存中,并加载后,我将加载的SWF页面(IT的子项的子剪辑的子项)选择到数组集合中。在更改页面时,我将缓存内容复制到显示页面的SWF Loader的影片剪辑中。

现在,当我在页面上突出显示并从页面上/向后导航并再次卷曲到我执行突出显示的页面:它显示了我所做的亮点。但是一旦我尝试在该页面上绘制另一个亮点,就会从页面上立即消失上一个亮点。

我怀疑在导航时拔出突出显示的TextSnapshot对象(对目标显示页面)不同于下次重绘/更新同一页面上的突出显示的突出显示。虽然两个对象的TextSnapshot对象ID相同。

以下是一些代码段:

要从应用程序存储器中缓存的SWF Loader对象中复制内容:

    private function copyPageContent():void

    {

        var contentCollection:ArrayCollection = new ArrayCollection();

        _pageContentVO = new PageContentVO();

        _pageContentVO.contentHeight = MovieClip(_swfPageLoader.content).height;

        _pageContentVO.contentWidth = MovieClip(_swfPageLoader.content).width;



        var count:int = MovieClip(_swfPageLoader.content).numChildren;                

        for(var i:int=0;i<count;i++)

        {

            var dispObject:DisplayObject = MovieClip(_swfPageLoader.content).removeChildAt(0);                

            contentCollection.addItem(dispObject);

        }



        _pageContentVO.pageContentCollection = contentCollection;

        _swfPageLoader = null;

    }
.

将内容复制到显示页面的SWF加载器:

    private function copyContent(pageContentVo:PageContentVO):void

    {

        for(var i:int = 0;i<pageContentVo.pageContentCollection.length;i++)

        {

            var dispObject:DisplayObject = pageContentVo.pageContentCollection.getItemAt(i) as DisplayObject;

            MovieClip(this.content).addChild(dispObject);

        }

        this.content.height = this.height;

        this.content.width = this.width;

    }
.

在此之后,我手动调度SWF加载器的完整,并在该事件的处理程序中,我采取文本快照拍摄对象。(explightManager.as)

代码我用来手动绘制高亮(使用页面上的鼠标拖动)。

    public function setHighlight():void

    {

        removeAll();

        if(_textSnapShot!=null && _textSnapShot.getText(0,_textSnapShot.charCount)!="")

        {                

            if(_isCoveredTextSelectedAtAnyInstance)

            {

                _textSnapShot.setSelected(_beginIndex,_endIndex+1,false); //this is the global variable to the class

            }

            else

            {

                _textSnapShot.setSelectColor(0xfff100);

                _textSnapShot.setSelected(_beginIndex,_endIndex+1,true);

            }

            if(saveHighlight)

            {

                countHighlightedSegments();

            }                

        }            

    }
.

代码我用来重绘之前返回页面时之前绘制的突出显示:

    public function showHighlights(textSnapShot:TextSnapshot,currentPageNum:int):void

    {            

        if(currentPageNum >= 0)

        {

            textSnapShot.setSelected(0,textSnapShot.charCount,false);

            var pageVO:PageVO = _model.eBookVO.eBookPagesVO.getItemAt(currentPageNum) as PageVO;

            var objColl:ArrayCollection = new ArrayCollection();

            objColl.source = pageVO.highLightSelection;

            for(var i:int=0;i<objColl.length;i++)

            {

                var highlightVO:HighlightVO = new HighlightVO();

                highlightVO.beginIndex = objColl.getItemAt(i).beginIndex;

                highlightVO.endIndex = objColl.getItemAt(i).endIndex;

                setHighlightedSegment(textSnapShot,highlightVO.beginIndex,highlightVO.endIndex);

            }

        }

    }



    private function setHighlightedSegment(textSnapShot:TextSnapshot,beginIndex:int,endIndex:int):void

    {

        textSnapShot.setSelectColor(0xfff100);

        textSnapShot.setSelected(beginIndex,endIndex,true);

    }
.

期待您的支持解决此问题。

问候,

js

有帮助吗?

解决方案

What you're doing is not 'caching', it's preloading previous/next pages. Also, what you're doing is really bad practice. I'm not even sure why you're casting these things into MovieClips unless the SWFs are that; if they're Flex SWFs, they'll be UIComponents. I would recommend you rethink your approach. I wouldn't even bother copying the children or anything over. Once the browser loads a SWF, it is now part of the browser cache, meaning the next time it's requested, it won't actually download it.

If you want to 'cache' your SWFs for a quicker next/previous page flipping, I would recommend you use something like SWFLoader to just load the other SWFs without actually adding it to the display, then removing it from memory. That will cache the SWFs for you in the browser. Then when the user click previous/next, just change the url of the main swfloader of the currently displayed page and it will load it up really quickly. No downloading since it's already cached, it will just need to instantiate.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top