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); |
||
![]() |
![]() |
![]() |
#2 | ||
|
|||
Flitig postare
|
Du skall sätta egenskaper på dina holder clips efter loadClip laddat klart.
Jag skulle rekommendera att du kör med MovieClipLoader istället och använder dess onLoadInit event. |
||
![]() |
![]() |
![]() |
#3 | ||
|
|||
Nykomling
|
Citat:
Använder onLoadInit också.. se sista kodstycket i första kodrutan.. |
||
![]() |
![]() |
![]() |
#4 | ||
|
|||
Flitig postare
|
Jo...nu ser jag att du kört med MCL, dock så har du inte använt onLoadInit för att sätta egenskaper och handlers då bilden laddat klart.
Du skapar din MCL och lyssnare utanför funktionen, vilket inte verkar riktigt korrekt. För varje clip du skapar skall du ha en ny MCL och lyssnare. Du kan du sätta nummer från "i" genom att passa den i lyssnar objektet som så: preload.num=i; Sedan i onLoadInit kan du lägga till variabeln för ditt clip med: target.num=this.num; |
||
![]() |
![]() |
Svara |
|
|