开发者

trouble separating loader array and array for grid of images

My problem is that I can't figure out how to decouple the loader from this loadNewRow function. Ideally, I'd like to figure out how to load all the swf's give them dynamic names... like thmb1loaded, thmb2loaded, thmb3loaded.. push into an a ("loaded") array and then have that be used to build the grid.

Right now, its loading them every time the loadnewrow function fires. I'm sure its a simple matter of iterating a .name within a contentloaderinfo .onComplete when each swf is loaded... anyhelp would be appreciated this has been driving me crazy last couple of days..

var filePaths:Array=["thmb1.swf","thmb2.swf","thmb3.swf","thmb4.swf", "thmb5.swf", "thmb6.swf",
 "thmb7.swf","thmb8.swf", "thmb9.swf", "thmb10.swf", "thmb11.swf" ];

function loadImages3(event:MouseEvent):void {
    TweenLite.to(pic, 8, {alpha:0, ease:Expo.easeInOut});// dim image container
    trace("loadImages3 fired ---------------------------------------------------------")
    unloadImages3resize(); loadImages3Flag=true;
    var randomScale:Number = .3 + Math.random();trace("in loadimages3 function randomScale is now.. " + randomScale);
    var stage_w=stage.stageWidth;trace("in loadimages3 function stage_w is = " + stage_w);
    var stage_h=stage.stageHeight;trace("in loadimages3 function stage_h is = " + stage_h);
    var thumbWidth:Number=240;var thumbHeight:Number=155;//var randomScale:Number=.45;
    var scaleThumbs:Number=randomScale;
    var finalRandomScaledWidth:Number=thumbWidth*scaleThumbs;
    var finalRandomScaledHeight:Number=thumbHeight*scaleThumbs;
    var clipsFitX=Math.floor(stage_w/finalRandomScaledWidth);
    trace("in loadimages3 function finalRandomScaledWidth is = " + finalRandomScaledWidth);
    var clipsFitY=Math.floor(stage_h/finalRandomScaledHeight);
    trace("in loadimages3 function finalRandomScaledHeight is = "  + finalRandomScaledHeight);
    var clipsFitXTotal:Number = clipsFitX+1; // add extra one on the horizontal
    var clipsFitYTotal:Number = clipsFitY+2; // add extra two on the vertical
    trace ("ClipsFitXtotal) = " +clipsFitXTotal, "(clipsFitYTotal) = " + clipsFitYTotal);
    loadnewRow(clipsFitXTotal, clipsFitYTotal,randomScale,finalRandomScaledHeight, finalRandomScaledWidth );
}

function loadnewRow(clipsFitXTotal:Number, clipsFitYTotal:Number, randomScale:Number, 
                    finalRandomScaledHeight:Number, finalRandomScaledWidth:Number):void {
    trace("loadnewRow fired ---------------------------------------------------------");
    trace("randomScale out of loop but in loadnewRo开发者_Python百科w function loop =" + randomScale);
    for (var z:Number =0; z < clipsFitYTotal; z++) {
        for (var b:Number = 0; b < clipsFitXTotal; b++) {
            var ldr:Loader = new Loader();
            var randomSelection = Math.floor( (Math.random()*filePaths.length) );
            ldr.load(new URLRequest (filePaths[randomSelection]));
            ldr.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
            ldr.scaleX=ldr.scaleY=randomScale;//trace("randomScale in the loop is =" + randomScale);
            ldr.y=finalRandomScaledHeight*z;//trace("finalRandomScaledHeight*z =" + ldr.y);
            ldr.x=finalRandomScaledWidth*b;//trace("finalRandomScaledWidth*b =" + ldr.x);
            ldr.alpha=.8;
            //trace("[ldr] = number of children = " + ldr.numChildren);
            //trace("[THIS] = number of children = " + this.numChildren);
            //trace("[THIS] name is = " +this.name);
            ldr.cacheAsBitmap = true;
            //thumbholder.addChild(ldr);
            addChildAt(ldr,1);
            filePaths.splice(randomSelection, 1);
            if (filePaths.length==0) {
                filePaths.push("thmb1.swf","thmb2.swf","thmb3.swf","thmb4.swf","thmb5.swf",
                    "thmb6.swf","thmb7.swf","thmb8.swf", "thmb9.swf",
                "thmb10.swf", "thmb11.swf");
            }
        }
    }
}


I suggest you to use some library/framework to simplifiy things. As I use splinklibrary here is some exemplary code to solve your problem with the aid of splinklibrary:

    public function Test() {
        var filePaths : Array = ["thmb1.swf","thmb2.swf","thmb3.swf"];

        var q : IQ = new Q();
        q.register(QCompleteEvent.COMPLETE, onComplete);
        for each (var path : String in filePaths) {
            q.add(new QLoader(new URLRequest(path)));
        }
        q.start();
    }

    private function onComplete(e : QCompleteEvent) : void {
        var displays : Array = new Array();
        var q : IQ = IQ(e.getSource());
        for each (var loader : QLoader in q.getItems()) {
            displays.push(addChild(loader.getContent()));
        }

        arrange(displays);
        show(displays);
    }

    private function arrange(displays : Array) : void {
        // put in your code to arrange the loaded displayobjects
    }

    private function show(displays : Array) : void {
        // put in your code to tween the loaded displayobjects
    }

Of course you can reach your goal without a library too, but the point is that a library often helps to keep your code simple and concise.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜