Monday, May 6, 2013

旅行书-技术难题解决之道

1.缩略图部分显示不出:
查看了一些blog后,通过image cache这个主题,启发了优先使用localThumb,而非thumburl

2. 拖动不灵敏:
查看了scroll相关主题后,通过自定义scroll list,发现增加fudge这种方式可以有更好的效果

Sunday, May 5, 2013

监听application外的鼠标事件

查看SandboxMouseEvent API

change verticalScrollPosition programmatically

在鼠标拖动到底部之前进行VSP计算,增加一个fudge,具体方法:
private function addMove(event:MouseEvent) {
    var currentMouseX:Number = event.stageX;
    var currentMouseY:Number = event.stageY;
    const fudge:Number = 20; 
    var needScroll:Boolean = !vpBound.contains(currentMouseX, currentMouseY + fudge);
if(needScroll) {
                    // drag out the top viewport
                    if(currentMouseY < 0) {
                        vp.verticalScrollPosition = 0;
                        return;
                    }
                   
                    //first child in the viewport
                    if(typicalBounds.y > 0 && currentMouseY < typicalBounds.y) {
                        vp.verticalScrollPosition = 0;
                        return;
                    }
                   
                    //drag out the bottom viewport
                     if((currentMouseY > lastChildBounds.y) && isInBottomView()) {
                        vp.verticalScrollPosition = -vp.getVerticalScrollPositionDelta(NavigationUnit.HOME);
                        return;
                    } 
                   
                    vp.layout.verticalScrollPosition += SCROLL_DELTA*direction;
                    //container.verticalScrollPosition += SCROLL_DELTA*direction;
                    Logger.gInfo("vp.verticalPosition: ", vp.verticalScrollPosition);
                }
               
                oldMovingMouseY = currentMouseY;
}

使用ImageCache, 解决缩略图显示不出来问题

问题:上传页在上传完中图后,可以直接到下一步,这时候会继续大图上传操作,导致有些图片在行程设置上显示不出来。
解决方法:在上传中图前,已经对内存图片进行了缓存,在行程设置中优先使用localThumb,避免BitmapImage重新下载图片

图片缓存相关blog:
http://thanksmister.com/2009/01/29/flex-imagecache-a-cheap-way-to-cache-images/
http://flexponential.com/2010/01/10/caching-images-loaded-from-a-spark-item-renderer/