Connecting Tech Pros Worldwide Help | Site Map

Help with arrays

Member
 
Join Date: Aug 2008
Posts: 41
#1: Jul 6 '09
Hi guys ,
I have got lost a bit with this flash i am doing at moment , i will try to explain the best i can and i'll post the code as well so u can see what i've done .
I am using Action script 2, i have an XML with photos , at the moment are 7 photos in there. The code i have at the moment just simply reads from the xml all the photos adn display them in a movie clip .

This is the code so far :
Expand|Select|Wrap|Line Numbers
  1.  step_sel_img.onRelease=function(){
  2. myPhoto = new XML();
  3. myPhoto.ignoreWhite = true;
  4. thumbnails._visible=true;
  5. thumbnails.background=0xD8D8D8;
  6. myPhoto.onLoad = function(success) {
  7.     //portfolioTag = this.firstChild;
  8.     numimages = this.firstChild.childNodes.length;
  9.     spacing = 70;
  10.     for (i=0; i<numimages; i++) {
  11.         this.picHolder = this.firstChild.childNodes[i];
  12.         this.thumbHolder = thumbnails.createEmptyMovieClip("thumbnail"+i, i);
  13.         this.thumbHolder._x = i*spacing;
  14.         this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
  15.         this.thumbLoader.loadMovie(this.picHolder.attributes.thmb);
  16.         this.thumbHolder.title = this.picHolder.attributes.title;
  17.         this.thumbHolder.main = this.picHolder.attributes.main;
  18.         this.thumbHolder.onRelease = function() {
  19.             grass_bcg.visible=true;
  20.             loader.loadMovie(this.main);
  21.             title_txt.text = " Price = " + this.title;
  22.         };
  23.     }
  24. };
  25. myPhoto.load("xmlphoto.xml") 
There is a button called "step_sel_img" which when pressed loads all the images in a movie clip called " thumbnails ".
Everything is working fine .
Now ..what i want to do is :
i want to set up an array that holds all the images ( before to display them ), and for each of the image i also have other fields like for ex:
image1 contains , name , price, thumbnail, main
The reason i want to do this is that when all images are loaded in the array, then i can set up some button back and forward to display like 3 at the time instead of all.
So basically i need an arary of array ( 2d array) , bust i got lost doing this
I'll put the code below to show u what i've tried to do , and if anyone can tell me what i'am doing wrong .
Expand|Select|Wrap|Line Numbers
  1. step_sel_img.onRelease=function(){
  2. myPhoto = new XML();
  3. myPhoto.ignoreWhite = true;
  4. thumbnails._visible=true;
  5. thumbnails.background=0xD8D8D8;
  6. myPhoto.onLoad = function(success) {
  7.     //portfolioTag = this.firstChild;
  8.     numimages = this.firstChild.childNodes.length;
  9.     spacing = 60;
  10.     for (i=0; i<numimages; i++) {
  11.         this.picHolder = this.firstChild.childNodes[i];
  12.         this.thumbHolder = thumbnails.createEmptyMovieClip("thumbnail"+i, i);
  13.         this.thumbHolder._x = i*spacing;
  14.         this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
  15.         // testing --------------
  16.         //images[i]=i;
  17.         images = new Array (3);
  18.         images[0]= this.picHolder.attributes.title;
  19.         images[1]= this.picHolder.attributes.price;
  20.         images[2]= this.picHolder.attributes.main;
  21.         images[3]= this.picHolder.attributes.thmb;
  22.         lastimage=i;
  23.         newArray = new Array();
  24.         //newArray[i].push(images)
  25.         set("countArray"+i, images);
  26.             trace (countArray);
  27.  
  28.         //for (var a=0;a<4;a++)
  29. //        {
  30. //            this.picHolder = this.firstChild.childNodes[a];
  31. //            this.thumbHolder = thumbnails.createEmptyMovieClip("thumbnail"+a, a);
  32. //            this.thumbHolder._x = i*spacing;
  33. //            this.thumbLoader = this.thumbHolder.createEmptyMovieClip("thumbnail_image", 0);
  34. //            this.thumbLoader.loadMovie(images[a][3]);
  35. //            this.thumbHolder.title = images[a][0];
  36. //            this.thumbHolder.main = images[a][2];
  37. //            
  38. //        }
  39.         // testing ------------------
  40.  
  41.         this.thumbLoader.loadMovie(this.picHolder.attributes.thmb);
  42.         this.thumbHolder.title = this.picHolder.attributes.title;
  43.         this.thumbHolder.main = this.picHolder.attributes.main;
  44.         this.thumbHolder.onRelease = function() {
  45.             grass_bcg.visible=true;
  46.             loader.loadMovie(this.main);
  47.             title_txt.text = " Price = " + this.title;
  48.         };
  49.     }
  50.     trace (images);
  51.  
  52. };
  53. myPhoto.load("xmlphoto.xml");
  54. };
  55.  
the code i have tried is between the testing comments
Thanks.
Member
 
Join Date: Aug 2008
Posts: 41
#2: Jul 7 '09

re: Help with arrays


Hi guys , found a solution for that , for creating a 2d array
basically this 2 lines of code , first creates the main array , then for each index of that arrya i assign more values for it .
Not sure if this is the right way to do it , but it works for me .
Expand|Select|Wrap|Line Numbers
  1. images[i]=i;
  2.         images[i] = [this.picHolder.attributes.title, this.picHolder.attributes.price,this.picHolder.attributes.main,this.picHolder.attributes.thmb];
Reply


Similar Flash / Actionscript bytes