Unique assignment of a nested function within an array loop (i know it's bad)

Hey guys,

I’m having probs with preloading swfs into an array. Basically, it’s the preloader for the individual swfs that are loaded on demand by the user into each’s respective attached movieclip in the array. I know it’s naughty, but i’ve put a function in a function (I hear this is evil). Anyway, each iteration in the the putBtn function is uniquely assigned(.num = i etc etc), but i’ve got a preloading function (preloadContainer) within PutBtn. How would i go about uniquely assigning each iteration of this, so that i can refer in the preloadContainer function to the particular Putbtn clicked?

excuse my poor code. i’ve only learnt arrays a couple of days ago. :stuck_out_tongue:

i’ve seen senocular’s helpful FAQ on uniquely assignment of loop iterations (thanks senocular :wink: ), but i’m having probs with this one…

any ideas guys?

ps I’m guessing that for the most part, the bit you should focus on is the innards of the PutBtn button function.


var imageArray:Array = new Array();
imageArray[0] = largePanel.panel1_mc.paul.img1;
.. to ... (shortened this bit)
imageArray[32] = largePanel.panel1_mc.kohei.img11;

 for (var i:Number = 0; i < imageArray.length; i++) {   
    var imgHeight:Number = imageArray*._y;
    var imageSel = imageArray*;
    var putBtn:MovieClip = imageArray*.attachMovie("button", "button", 1000+i);
    putBtn.num = i;
    imageSel.createEmptyMovieClip("vid", i);
    var vidBtn:MovieClip = imageArray*.attachMovie("button", "vid", 100+i);
    vidBtn.num = i;
    var slideTo:Number = -200;   
   
    putBtn.onRelease = function() {       
        for (var i:Number = 0; i < imageArray.length; i++) {
            imageArray*.button._visible = true;
        };
           var speedNum:Number = 0;
           var ycenter:Number = 150;
           var speed:Number = speedNum;
        largePanel.onEnterFrame = function() {
               var distance=_root._ymouse-ycenter;
               this._y+=(distance*speed);
               if (this._y > 0) this._y=-6597;
               if (this._y < -6597) this._y=0;
        };
        var speedNum:Number = 0;
        this._visible = false;
        imageArray[this.num].vidBtn._visible = true;
       
        //slider
        var theMove:Number = this.num * slideTo;
        largePanel.tween('_y', theMove, 0.5, easeInOutQuint, 0);
       
        //unload the vids
        for (var i:Number = 0; i < imageArray.length; i++) {
            imageArray*.vid.unloadMovie();
        };

        imageArray[this.num].vid.loadMovie("videos/" + this.num + ".swf", 100);
        attachMovie("preloader anim", "preloader_mc", 500, {_x:200, _y:0});
        onEnterFrame = preloadContainer;

        //load the individual vid
        function preloadContainer(){         
            var bytes_loaded = imageArray[1].vid.getBytesLoaded();
            var bytes_total = imageArray[1].vid.getBytesTotal();
            trace(bytes_loaded);
            imageArray[this.num].vid.stop();
            imageArray[this.num].vid._visible = false;
            if (bytes_total > 0){
                var percent_loaded = bytes_loaded/bytes_total;
                preloader_mc.value = percent_loaded;
            if (percent_loaded == 1){
                imageArray[1].vid.play();
                imageArray[1].vid._visible = true;
                preloader_mc.removeMovieClip();
                delete onEnterFrame;
                };
            };
        };
        //imageArray[this.num].vid.loadMovie("videos/" + this.num + ".swf", 100);
        return speedNum;
    };   
    //vid button
    vidBtn.onRelease = function() {
        var speedNum:Number = 1/7;
        var ycenter:Number = 150;
        var speed:Number = speedNum;
        largePanel.onEnterFrame = function() {
               var distance=_ymouse-ycenter;
               this._y+=(distance*speed);
               if (this._y > 0) this._y=-6597;
               if (this._y < -6597) this._y=0;
            if (_xmouse < 0 || _xmouse > 300) {
                speed -= speed/12;  
            };
            if (_xmouse >= 0 && _xmouse <= 300) {
                speed = 1/7;  
            };
        };
        for (var i:Number = 0; i < imageArray.length; i++) {
            imageArray*.vid._visible = false;
        };
        for (var i:Number = 0; i < imageArray.length; i++) {
            imageArray*.button._visible = true;
        };
        imageArray[this.num].vid.unloadMovie("videos/" + this.num + ".swf", 100);
        return speedNum;
    };
};

********:smirk: