A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Complicated Array not working properly.

  1. #1

    Complicated Array not working properly.

    Ok, i've gone and made a complex array script (probably more than it has to be), and it's not working perfectly. I have 5 sets of 4 buttons. i named then seta, setb, etc... and seta1, seta2, seta3, etc...

    When the movie is loaded, all of the 4 buttons link to the fourth image of that set (ie. all setc buttons link to setc4.jpg)

    I think this is because the array is applied to each button, and only the last actually works because the others become omited once the next is applied. I would like it to say:
    seta1 = link to seta1.jpg
    seta2 = link to seta2.jpg
    seta3 = link to seta3.jpg
    etc...

    here is the code:

    Code:
    my_array=new Array();
    for(i=0; i<4; i++) {
    	my_array [i] = (i + 1);
    	//var a = "seta"+my_array[i];
    	var a = this["seta"+my_array[i]];
    	var aImage = "images/seta"+my_array[i]+".jpg";
    	var aThumb = "images/thumbs/seta"+my_array[i]+".jpg";
    	var b = this["setb"+my_array[i]];
    	var bImage = "images/setb"+my_array[i]+".jpg";
    	var bThumb = "images/thumbs/setb"+my_array[i]+".jpg";
    	var c = this["setc"+my_array[i]];
    	var cImage = "images/setc"+my_array[i]+".jpg";
    	var cThumb = "images/thumbs/setc"+my_array[i]+".jpg";
    	var d = this["setd"+my_array[i]];
    	var dImage = "images/setd"+my_array[i]+".jpg";
    	var dThumb = "images/thumbs/setd"+my_array[i]+".jpg";
    	var e = this["sete"+my_array[i]];
    	var eImage = "images/sete"+my_array[i]+".jpg";
    	var eThumb = "images/thumbs/sete"+my_array[i]+".jpg";
    	//trace(a);
    	a.emptyMC.loadMovie(aThumb, 2);	
    	b.emptyMC.loadMovie(bThumb, 2);
    	c.emptyMC.loadMovie(cThumb, 2);
    	d.emptyMC.loadMovie(dThumb, 2);
    	e.emptyMC.loadMovie(eThumb, 2);
    	
    	a.onPress = function() {
    		_root.my_mc.loadClip(aImage, "_root.container");
    	};	
    	b.onPress = function() {
    		_root.my_mc.loadClip(bImage, "_root.container");
    	};	
    	c.onPress = function() {
    		_root.my_mc.loadClip(cImage, "_root.container");
    	};	
    	d.onPress = function() {
    		_root.my_mc.loadClip(dImage, "_root.container");
    	};	
    	e.onPress = function() {
    		_root.my_mc.loadClip(eImage, "_root.container");
    	};
    }
    Any help would be really appreciated, this is really hurting my head :P

    Oh, and if you'd like to see it in action, here it is: www.allegro.ca/a2005/ (click on portfolio)

    Thanks

  2. #2
    here's a simpler version of the code, it does the same thing, but just for seta...

    Code:
    arraySeta = new Array();
    for (i=0; i<4; i++) {
    	arraySeta[i] = (i+1);
    	//var a = "seta"+my_array[i];
    	var a = this["seta"+arraySeta[i]];
    	var aImage = "images/seta"+arraySeta[i]+".jpg";
    	var aThumb = "images/thumbs/seta"+arraySeta[i]+".jpg";
    	
    	a.emptyMC.loadMovie(aThumb, 2);
    	
    	a.onPress = function() {
    		_root.my_mc.loadClip(aImage, "_root.container");
    	};
    }

  3. #3
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    Code:
    arraySeta = new Array();
    for (i=0; i<4; i++) {
    	arraySeta[i] = (i+1);
    	var a = this["seta"+arraySeta[i]];
    	var aImage = "images/seta"+arraySeta[i]+".jpg";
    	var aThumb = "images/thumbs/seta"+arraySeta[i]+".jpg";
    	a.emptyMC.loadMovie(aThumb, 2);
    	a._id = aImage;
    	a.onPress = function() {
    		_root.my_mc.loadClip(this._id, "_root.container");
    	};
    }

  4. #4
    Thanks moagrius!

    Works perfectly now!

    plus, i understand.

    thanks

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