FAQ |
Kalender |
|
![]() |
#1 | ||
|
|||
Nykomling
|
Hey! Ive searched some but didnt find anything that could resolve my problem.
Im making a imagegallery, it first loads images from xml and then puts it in the object oImages. Then I make buttons with oImages.thumb, and place them and so on. The problem is that I know want to make the oImages.thumb onRelease events. but they cant find the corresponding i so the oImage.Image can be loaded. Ill post the code and some things that Ive tried.. Kod:
//temporary var nThumbWidth:Number = 120; var nThumbHeight:Number = 120; //Här kan du ställa in x och y positionen för första rutan var nThumbReset:Number = 10; //nImagesPerRow är antalet bilder du vill ha på varje rad var nImagesPerRow:Number = 5; var nImagesRowCheck:Number = 0; //Avståndet mellan dom olika thumbsen var nThumbXSpace:Number = 10; var nThumbYSpace:Number = 10; //dessa används i koden var nTotalImages:Number = 0; var nThumbXSpaceVar:Number = nThumbWidth + nThumbXSpace; var nThumbRowDiff:Number = nThumbHeight+ nThumbYSpace; var nThumbXPlace:Number = nThumbReset; var nThumbYPlace:Number = nThumbReset; var oImages:Object = new Object(); var x:XML = new XML(); x.ignoreWhite = true; _root.createEmptyMovieClip("holder",this.getNextHighestDepth()); _root.createEmptyMovieClip("fadeScreen",this.getNextHighestDepth()); _root.createEmptyMovieClip("bigImageHolder",this.getNextHighestDepth()); var loader:MovieClipLoader = new MovieClipLoader(); var preload:Object = new Object(); loader.addListener(preload); x.onLoad = function(success) { if(success) { //ladda till objekt var aPhotos:Array = this.firstChild.childNodes; for(var i:Number = 0;i<aPhotos.length;i++) { oImages["image"+i] = {image:aPhotos[i].attributes.image, thumb:aPhotos[i].attributes.thumb} nTotalImages+=1; } for(var i:Number = 0; i<nTotalImages; i++) { holder.createEmptyMovieClip("firstHolder"+i, holder.getNextHighestDepth()); holder["firstHolder"+i].createEmptyMovieClip("imageHolder",holder["firstHolder"+i].getNextHighestDepth()); loader.loadClip(oImages["image"+i].thumb,holder["firstHolder"+i].imageHolder); //placerar objekten holder["firstHolder"+i].imageHolder._x += nThumbXPlace; holder["firstHolder"+i].imageHolder._y += nThumbYPlace; //fixar avståndet till nästa i x led nThumbXPlace += nThumbXSpaceVar; //räknar upp för att kunna byta rads nImagesRowCheck +=1; //byter rad och nollställer if(nImagesRowCheck >= nImagesPerRow) { nImagesRowCheck = 0; nThumbXPlace = nThumbReset; nThumbYPlace += nThumbRowDiff; } //this returns 11 (the amount of objects) i want it to return the number for the specific button // holder["firstHolder"+i].onRelease = function () { // trace(i); // } //I figured that if the movement of the objects works, then shouldnt also this work? //but it didnt =/, is it maybe because imageHolder gets overwritten when i load something in it? // holder["firstHolder"+i].imageHolder.onRelease = function () { // trace(i); // } // //the trace works as it should, it coutns to 11 ((the amount of objects)) //trace(i); } if(!success) { trace("Fel vid laddning av xml"); } } } preload.onLoadInit = function(target){ //i thought that i could instead make the buttons when every objet was //loaded but the problem is that the i from the loop is lost (because the init is after the exec of the for loop) //and I can only retrive the name of the object through target // target.onRelease = function () { // trace(target); // // // // // / } x.load("test.xml"); Ive tried this Kod:
//this returns 11 (the amount of objects) i want it to return the number for the specific button // holder["firstHolder"+i].onRelease = function () { // trace(i); // } and this Kod:
//I figured that if the movement of the objects works, then shouldnt also this work? //but it didnt =/, is it maybe because imageHolder gets overwritten when i load something in it? // holder["firstHolder"+i].imageHolder.onRelease = function () { // trace(i); // } and this Kod:
preload.onLoadInit = function(target){ //i thought that i could instead make the buttons when every objet was //loaded but the problem is that the i from the loop is lost (because the init is after the exec of the for loop) //and I can only retrive the name of the object through target // target.onRelease = function () { // trace(target); // // // // // / och detta fungerar ju däremot Kod:
//the trace works as it should, it coutns to 11 ((the amount of objects)) //trace(i); |
||
![]() |
![]() |
Svara |
|
|