15 Replies Latest reply on Jul 3, 2007 3:46 PM by crazyjoemilan

    xml gallery

    woopig Level 1
      Anyone know how to assign a hyperlink to the images in a xml photo gallery? Thanks.
        • 1. Re: xml gallery
          crazyjoemilan Level 2
          is the XML photo gallery a component, or are you building this on your own?
          • 2. xml gallery
            woopig Level 1
            I am editing a xml & flash file already built. It has everything I need except links on my images
            • 3. Re: xml gallery
              woopig Level 1
              Come on.....someone has to know the answer to this. Please! :)
              • 4. Re: xml gallery
                crazyjoemilan Level 2
                Yeah, I know how to do that. Post some code or something, so I don't just have to guess what your format is.
                • 5. xml gallery
                  woopig Level 1
                  Thanks man. Here is the xml:

                  <?xml version="1.0" encoding="utf-8" standalone="yes"?>

                  <image>
                  <pic>images/image_1.jpg</pic>
                  <thumb>images/thumb_1.jpg</thumb>
                  </image>

                  • 6. xml gallery
                    woopig Level 1
                    Here is .as for frame 15[/B
                    • 7. Re: xml gallery
                      crazyjoemilan Level 2
                      image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
                      description = xmlNode.childNodes.childNodes[1].firstChild.nodeValue;
                      //
                      //adding links
                      //
                      link = xmlNode.childNodes.childNodes[2].firstChild.nodeValue;

                      the above adds your link and everything, but doesn't seem to call a function inside of the loop. I'll look at more of the code later, maybe I'm missing something. gotta get some real work done :(
                      • 8. Re: xml gallery
                        woopig Level 1
                        image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
                        description = xmlNode.childNodes.childNodes[1].firstChild.nodeValue;
                        //
                        //adding links
                        //
                        link = xmlNode.childNodes.childNodes[2].firstChild.nodeValue;

                        I wasn't sure if this was even correct. I just threw it in there to see if it would help.
                        I appreciate you taking a look at this when you get more time.

                        Mark
                        • 9. Re: xml gallery
                          crazyjoemilan Level 2
                          Having 3 different frames with that much .as on each of them is going to cause you procedural headaches. Is there anyway you can combine the actionsctipt, so you're not having to declare single variables multiple times? Thats really the first step, then the next part becomes much more simple.
                          • 10. Re: xml gallery
                            woopig Level 1
                            Ok here is a condensed version....still has .as on three frames but much shorter: How do I add the hyperlink to the thumnail pic?

                            frame 1

                            //Load the XML data
                            xmlData = new XML(); //Create new XML object to load the data into
                            xmlData.ignoreWhite = true;
                            xmlData.load("data.xml"); //Load the data.xml file. Change path here as needed!
                            xmlData.onLoad = loadXML; //After data is loaded call the loadXML() function

                            //Function called on XML data load completion
                            function loadXML(loaded:Boolean) {
                            if (loaded) {
                            //Load succesfull
                            xmlNode = this;
                            } else {
                            //Error by loading
                            txtLoadText.htmlText = "XML file failed to load!";
                            stop();
                            }
                            }


                            frame 2

                            var noOfImages:Number = xmlNode.childNodes.length; //Total number of images in the XML file
                            var i:Number; //Variable for internal use
                            var thumbHolder:MovieClip; //Movieclip including all the thumbnails
                            var thumbs:Array = []; //Array holding the information about the thumbnails
                            var currentY:Number = 10; //Y-axis position of the curretly loaded thumbnail
                            var currentX:Number = 10; //X-axis position of the curretly loaded thumbnail
                            var stepX:Number = 120; //Distance between two thumbnails (between the upper-left corners)
                            var noOfCompletedThumbs:Number = 0; //Number of loaded thumbnails

                            //Create an empty movieclip that will contain all the thumbnails
                            thumbHolder = this.createEmptyMovieClip("thumbHolder",this.getNextHighestDepth());
                            //Hide untill all thumbnails are loaded
                            thumbHolder._visible = false;

                            //Update the preloader text
                            txtLoadText.htmlText = "loading thumbnails... " + noOfCompletedThumbs + " of " + noOfImages;

                            //Load the thumbnails
                            for(i = 0; i < noOfImages; i++) {
                            //Get the thumbnail frame from the library and attache it to the stage
                            thumbs = thumbHolder.attachMovie("mcThumb", "thumb"+i,thumbHolder.getNextHighestDepth());
                            //Position it
                            thumbs
                            ._x = currentX;
                            thumbs ._y = currentY;

                            //Calculate the position for the next thumbnail
                            currentX += stepX;

                            //Create a MovieClipLoader and Listener for each thumbnail
                            //in order to monitor the load process
                            var tcl:MovieClipLoader = new MovieClipLoader();
                            var tlistener:Object = new Object();

                            tlistener.idNum = i;
                            //Callback: called when the image is fully
                            //loaded and starts displaying
                            tlistener.onLoadInit = function(target_mc:MovieClip) {
                            target_mc.idNum = this.idNum;

                            //Increment the counter for already loaded thumbnails
                            noOfCompletedThumbs++;
                            //Update preloader text
                            txtLoadText.htmlText = "loading thumbnails... " + noOfCompletedThumbs + " of " + noOfImages;
                            if(noOfCompletedThumbs == noOfImages) {
                            //All the thumbnails are fully loaded
                            //proceed to the main movie
                            thumbHolder._visible = true;
                            gotoAndPlay("loadImages");
                            };

                            target_mc.onRelease = function() {
                            //Callback: called when the user clicks one thumbnail

                            //Load the corresponding image
                            loadImage(this.idNum);
                            }
                            };

                            //Callback: Called when one of the images
                            //finishes loading
                            listener.onLoadComplete = function(target_mc:MovieClip) {
                            //Nothing in here yet
                            };

                            //Associate the listener with the movieclip loader
                            tcl.addListener(tlistener);
                            //Load the current thumbnail
                            tcl.loadClip(xmlNode.childNodes
                            .childNodes[1].firstChild.nodeValue, thumbs .mcImg);
                            }
                            stop();

                            frame 3

                            import mx.transitions.Tween;
                            import mx.transitions.easing.*;

                            var widthReserve:Number = 10; //Two times the border width around the main image
                            var heightReserve:Number = 10; //Two times the border height around the main image
                            var imageAreaWidth:Number = 380; //Width of the main image area
                            var imageAreaHeight:Number = 350; //Height of the main image area
                            var tweenSpeed:Number = 1; //Tweening speed for the thumbnail holder position tween
                            var destX:Number = thumbHolder._x; //Destination for the position tweening
                            var posTween; //Position tween handle

                            mcNavPrev.swapDepths(thumbHolder); //Bring the buttons in front of the thumbnails

                            //Set the button texts
                            mcNavPrev.txtCaption.htmlText = "«";
                            mcNavNext.txtCaption.htmlText = "»";

                            stop();


                            mcNavNext.onRelease = function() {
                            //"Next" button pressed

                            if(destX > -((noOfImages - 6) * stepX)){
                            //Not yet at the last image in the row => sweep the thumbnails to the left
                            destX -= stepX;
                            posTween.stop();
                            posTween = new Tween(thumbHolder, "_x", Strong.easeOut, thumbHolder._x, destX, tweenSpeed, true);
                            posTween.FPS = 50;
                            }
                            }

                            mcNavPrev.onRelease = function() {
                            //"Previous" button pressed
                            if(destX < 0){
                            //Not yet at the first position => sweep the thumbnails to the right
                            destX += stepX;
                            posTween.stop();
                            posTween = new Tween(thumbHolder, "_x", Strong.easeOut, thumbHolder._x, destX, tweenSpeed, true);
                            posTween.FPS = 50;
                            }
                            }
                            • 11. Re: xml gallery
                              crazyjoemilan Level 2
                              Okay,

                              this.attachMovie("linkageName", "instance1", this.getNextHighestDepth());
                              attachMovie returns a MovieClip (reference) not an array, so I get an error there.

                              After that,
                              target_mc.onRelease = function() {
                              //Callback: called when the user clicks one thumbnail
                              //Load the corresponding image
                              loadImage(this.idNum);
                              };

                              This is, I assume where you mean the button action to take place. I don't see the "loadImage()" function being defined anywhere. Is there hidden actionscript somewhere in the Christmas tree?
                              • 12. xml gallery
                                woopig Level 1
                                Sorry Helpy, I forgot to take that out. I no longer wish to have the thumbnail load an image somewhere. I just want the thumbnail to open a hyperlink in a new window. See here:

                                click me

                                (scroll to bottom of page to see thumbs)

                                Thanks
                                • 13. xml gallery
                                  crazyjoemilan Level 2
                                  give that one a whirl :)
                                  • 14. xml gallery
                                    woopig Level 1
                                    Gracias mcHelpson.

                                    Now this only allows each image to have the same link. What if I wanted different pics to have different links?
                                    • 15. Re: xml gallery
                                      crazyjoemilan Level 2
                                      you should just change the "link" attribute in the XML, and due to your loop --

                                      var st=xml.firstChild.childNodes
                                      .attributes.link

                                      when that num changes, so will your link. (at least it should).