Just nu i M3-nätverket
Jump to content

flash dynamiskt bild galleri


ZaK

Recommended Posts

Hej jag hittade en guide hur man skapar ett bild galleri i flash med ac3 länk

 

här är koden för hur bilden visas

 

   1.
     var imgNum:int = galleryData.image.length();
  2.

  3.
     var spacing:int = galleryData.@spacing;
  4.

  5.
     var cols:int = galleryData.@cols;
  6.

  7.
     var rows:int = Math.ceil(imgNum / cols);
  8.

  9.
     var imgCount:int = 0;
 10.

 11.
     var gallery:MovieClip = new MovieClip();
 12.
     addChild(gallery);
 13.

 14.
     buildGalleryGrid();
 15.

 16.
     var detailImage:Loader = new Loader();
 17.
     setupDetail();
 18.

 19.
     function setupDetail():void {
 20.
        detail.visible = false;
 21.
        detail.buttonMode = true;
 22.
        detail.closeMessage.mouseEnabled = false;
 23.
        detail.desc.mouseEnabled = false;
 24.

 25.
        detail.addChild(detailImage);
 26.
        // put border above loader;
 27.
        detail.addChild(detail.border);
 28.
        // make sure detail is above the gallery
 29.
        addChild(detail);
 30.

 31.
        detail.addEventListener(MouseEvent.CLICK, onCloseDetail,
 32.
                          false, 0, true);
 33.
     }
 34.

 35.
     function onCloseDetail(evt:MouseEvent):void {
 36.
        detailImage.unload();
 37.
        detail.visible = false;
 38.
     }
 39.

 40.
     function buildGalleryGrid():void {
 41.
        for (var py:int = 0; py <rows; py++) {
 42.
           for (var px:int = 0; px <cols; px++) {
 43.

 44.
              var thumb:Thumb = new Thumb();
 45.
              thumb.scaleX = thumb.scaleY = .5;
 46.

 47.
              // because the registration is centered we make sure
 48.
              // to position thumbs so that the upper left corner 
 49.
              // is at the registration point of the gallery movieClip
 50.

 51.
              thumb.x = thumb.width / 2 + (thumb.width + spacing) * px;
 52.
              thumb.y = thumb.height / 2 + (thumb.height + spacing) * py;
 53.

 54.
              gallery.addChild(thumb);
 55.

 56.
              // only add listeners and loader if thumb should be active
 57.
              if (imgCount <imgNum) {
 58.

 59.
                 var imageData:XML = galleryData.image[imgCount];
 60.

 61.
                 var loader:Loader = new Loader();
 62.
                 var path:String = galleryData.@folder + imageData.@thumb;
 63.
                 loader.x = 0;
 64.
                 loader.y = 0;
 65.
                 loader.load(new URLRequest(path));
 66.
                 loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
 67.
                                                 onThumbComplete);
 68.

 69.
                 thumb.addChild(loader);
 70.
                 thumb.addChild(thumb.border);
 71.

 72.
                 thumb.buttonMode = true;
 73.

 74.
                 thumb.detail = galleryData.@folder + imageData.@detail;
 75.
                 thumb.desc = imageData;
 76.

 77.
                 thumb.addEventListener(MouseEvent.CLICK, onThumbClick,
 78.
                                   false, 0, true);
 79.

 80.
                 thumb.addEventListener(MouseEvent.ROLL_OVER, onThumbOver,
 81.
                                   false, 0, true);
 82.

 83.
                 thumb.addEventListener(MouseEvent.ROLL_OUT, onThumbOut,
 84.
                                   false, 0, true);
 85.
              } else {
 86.

 87.
                 // thumb is inactive
 88.
                 thumb.alpha = .5;
 89.
              }
 90.
              imgCount++;
 91.
           }
 92.
        }
 93.

 94.
        // center the gallery clip
 95.
        gallery.x = stage.stageWidth/2 - gallery.width/2;
 96.
        gallery.y = stage.stageHeight/2 - gallery.height/2;
 97.

 98.
        // position and setup gallery title
 99.
        galleryTitle.autoSize = TextFieldAutoSize.LEFT;
100.
        galleryTitle.text = galleryData.@title;
101.
        galleryTitle.x = gallery.x-2;
102.
        galleryTitle.y = gallery.y-50;
103.
     }
104.

105.
     function onThumbComplete(evt:Event):void {
106.
        var img:Bitmap = Bitmap(evt.target.content);
107.
        img.x = -img.width/2;
108.
        img.y = -img.height/2;
109.
     }
110.

111.
     function onThumbOver(evt:MouseEvent):void {
112.
        var thumb:MovieClip = MovieClip(evt.target);
113.
        gallery.addChild(thumb);
114.
        thumb.scaleX = thumb.scaleY = 1;
115.
     }
116.

117.
     function onThumbOut(evt:MouseEvent):void {
118.
        evt.target.scaleX = evt.target.scaleY = .5;
119.
     }
120.

121.
     function onThumbClick(evt:MouseEvent):void {
122.
        detail.visible = false;
123.

124.
        detail.desc.condenseWhite = true;
125.
        detail.desc.htmlText = evt.currentTarget.desc;
126.

127.
        try {
128.
           detailImage.close();
129.
        } catch (err:Error) {
130.
           // this is here in case another image
131.
           // is loaded before the detail has finished
132.
           // loading (not possible with current layout)
133.
           // trace(err);
134.
        }
135.
        detailImage.load(new URLRequest(evt.currentTarget.detail));
136.
        detail.visible = true;
137.
     }

 

men jag skulle behöva hjälp med att ändra om koden lite så att istället för att det visar titeln på bilden så ska den läsa ur en textfil där man kan ändra och skriva vad man vill

 

tack på förhand

Link to comment
Share on other sites

då ska du inte be om hjälp utan lösa uppgiften på egen hand.

rent krasst är xml endast ett format i en textfil :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...