A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] swapDepths - spot the flaw?!

  1. #1
    Senior Member
    Join Date
    Oct 2004
    Location
    London
    Posts
    186

    resolved [RESOLVED] swapDepths - spot the flaw?!

    I have loaded several large images into clips at different levels within a container clip.
    I have thumbnails corresponding to these larger images. When I click a thumbnail, I want the right image to jump to the top of the stack. I'm doing this by calculating which image is currently at the top, and then swapping depths.

    The code below works for about 10+ clicks - the right image fades in ontop of the previous image,... but then it starts to mess up, and other images are visible underneath the fade in effect.

    Can anyone see what's wrong just from looking at the code?

    Actionscript Code:
    function makeBtns(tot:Number) {
        for (p=1;p<=tot;p++) {
            if (p==1) {
                _root["loader"]["ntemp"+p]._alpha = 100;//set the first picture as visible...
            } else {
                _root["loader"]["ntemp"+p]._alpha = 0;//everything else invisible.
            }
            _root["view"]["thmb_mc"+p].onPress = function() {
                id = this._name.substr(7,2);
                fadeIn(id,tot);
            }
        }
    };

    function fadeIn(pic:Number,tot:Number) {
        picin = _root["loader"]["ntemp"+pic];
        prev = _root["loader"].getInstanceAtDepth(tot);
        picin.swapDepths(prev);
        for (v=1;v<=tot;v++) {
            if (v==pic) {
                _root["loader"]["ntemp"+pic]._alpha = 0;
            }
        }
        picin.onEnterFrame = function() {
            if (this._alpha < 100) {
                this._alpha += 15;
            } else {
                delete picin.onEnterFrame;
            }
        }
    };

    As always, thanks for any suggestions.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    function makeBtns(tot:Number) {
    	for (p=1; p<=tot; p++) {
    		if (p == 1) {
    			_root["loader"]["ntemp"+p]._alpha = 100;
    		} else {
    			_root["loader"]["ntemp"+p]._alpha = 0;
    		}
    		_root["loader"]["ntemp"+p].swapDepths(p);
    		_root["view"]["thmb_mc"+p].tot = tot;
    		_root["view"]["thmb_mc"+p].onPress = function() {
    			id = this._name.substr(7, 2);
    			fadeIn(id,this.tot);
    		};
    	}
    }

  3. #3
    Senior Member
    Join Date
    Oct 2004
    Location
    London
    Posts
    186
    Hi Dawsonk,

    Thank you for your suggestion... I used the code you posted but, unfortunately, the same thing is happening. I think I'm setting the alpha to 0 in the wrong place, or something? I will keep playing around with the code...

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    function fadeIn(pic:Number, tot:Number) {
    	picin = _root["loader"]["ntemp"+pic];
    	prev = _root["loader"].getInstanceAtDepth(tot);
    	picin.swapDepths(prev);
    	for (v=1; v<=tot; v++) {
    		if (v == pic) {
    			_root["loader"]["ntemp"+pic]._alpha = 0;
    		}
    	}
    	picin.onEnterFrame = function() {
    		if (this._alpha<100) {
    			this._alpha += 15;
    		} else {
    			delete this.onEnterFrame;
    		}
    	};
    }

  5. #5
    Senior Member
    Join Date
    Oct 2004
    Location
    London
    Posts
    186

    resolved

    Hi Dawsonk, thanks for your help again. I made the changes as suggested and also changed the functions a little and now it seems to be working fine!

    Actionscript Code:
    function makeBtns(tot:Number) {
        for (p=0;p<tot;p++) {
            _root["loader"]["ntemp"+p].swapDepths(p);
            _root["view"]["thmb_mc"+p].tot = tot;
            _root["view"]["thmb_mc"+p].onPress = function() {
                id = this._name.substr(7,2);
                pictofade = _root["loader"]["ntemp"+id];
                id2 = _root["loader"].getInstanceAtDepth(tot);
                if (id2 != pictofade) {
                    pictofade._alpha = 0;
                    pictofade.swapDepths(id2);
                    id2.swapDepths(tot-1);
                }
                fadeIn(pictofade);
            }
        }
    };

    function fadeIn(picin:MovieClip) {
        picin.onEnterFrame = function() {
            if (this._alpha < 100) {
                this._alpha += 10;
            } else {
                delete this.onEnterFrame;
            }
        }
    };

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center