9 Replies Latest reply on Apr 21, 2006 7:42 AM by kglad

    load movie and make clickable

    codescodescodes Level 1
      Hi everyone. I'm having trouble loading a movie into a movie clip and making it clickable. I'm not sure if this is even possible. Here's my code:

      // I have a movie clip on the stage with the name pictureHolder_mc.

      pictureHolder_mc.loadMovie("picture/imag1.jpg");
      pictureHolder_mc.onRelease = function():Void {
      trace("button clicked");
      };

      The image loades but the image is not clickable. Can someone tell me what I'm doing wrong. Thanks.
        • 1. Re: load movie and make clickable
          kglad Adobe Community Professional & MVP
          you have to wait until loading is complete to define mouse handler code.
          • 2. Re: load movie and make clickable
            codescodescodes Level 1
            Hi kglad. Thanks for helping me out, but I still can't seem to make it work. Here's what I did.

            pictureHolder_mc.onLoad = function():Void {
            this.onRelease = function():Void {
            trace("button is now clickable");
            };
            };
            pictureHolder_mc.loadMovie("pictures/image1.jpg");
            • 3. Re: load movie and make clickable
              codescodescodes Level 1
              maybe if I give you all my code, you can find out what's wrong with it. Here's what I'm having problems with:
              • 4. Re: load movie and make clickable
                codescodescodes Level 1
                Thanks for all your trouble. Really appreciate it.
                • 5. Re: load movie and make clickable
                  kglad Adobe Community Professional & MVP
                  again, you must wait until loading is complete before defining handlers for a target movieclip. use preloader code or the onLoadInit() handler for the moviecliploader class.
                  • 6. Re: load movie and make clickable
                    codescodescodes Level 1
                    ok. Thanks for the advice kglad. I've changed my code to use the MovieClipLoader class, but now I have another question. What I'm trying to do is to pull information from an xml file and load the info into a movie clip and make that movie clip clickable. I have a loop that will retrieve the information from the xml. In the loop I create a MovieClipLoader instance and create a listener for it that, when clicked will redirect the user to a specified website that was retrieved from the xml file. Here's my code:

                    var linkXML:XML = new XML();
                    linkXML.ignoreWhite = true;
                    linkXML.onLoad = function():Void {
                    var xmlLength:Number = this.firstChild.childNodes.length;
                    for (var i:Number = 0; i < xmlLength; i++) {
                    var imageLinkName:String = "imageLink" + i;
                    _root.attachMovie("MC_imageLink", imageLinkName, _root.getNextHighestDepth());
                    var xStart:Number = 30;
                    var yStart:Number = 0;
                    var ySpacing:Number = _root[imageLinkName]._height + 5;
                    _root[imageLinkName]._x = xStart;
                    _root[imageLinkName]._y = yStart + i * ySpacing;
                    var itemImage:String = this.firstChild.childNodes .firstChild.firstChild.nodeValue;
                    var itemLink:String = this.firstChild.childNodes
                    .lastChild.firstChild.nodeValue;
                    var itemDescription:String = this.firstChild.childNodes .lastChild.previousSibling.firstChild.nodeValue;
                    var itemName:String = this.firstChild.childNodes
                    .firstChild.nextSibling.firstChild.nodeValue;
                    var mcLoader:MovieClipLoader = new MovieClipLoader();
                    var mcLoaderListener bject = new Object();
                    mcLoaderListener.onLoadComplete = function(mc:MovieClip):Void {
                    mc.onRelease = function():Void {
                    getURL(itemLink);
                    };
                    };
                    mcLoader.loadClip(itemImage, _root[imageLinkName].pictureHolder_mc);
                    mcLoader.addListener(mcLoaderListener);
                    _root[imageLinkName].name_txt.text = itemName;
                    _root[imageLinkName].description_txt.text = itemDescription;
                    }
                    };
                    linkXML.load("linkInfo.xml");

                    I know what's happening. When the MovieClipLoader.onLoadComplete is triggered, it is triggered after the loop has finished, therefore only the last piece of data is being sent to the code in MovieClipLoader.onLoadComplete function. In other words, if I run a trace(itemLink) in the MovieClipLoader.onLoadComplete function I get:

                    http://www.shermanswim.com/
                    http://www.shermanswim.com/
                    http://www.shermanswim.com/

                    instead of:

                    http://www.mark-yieh.com/
                    http://www.dooster.com/
                    http://www.shermanswim.com/

                    My question is how do I get the MovieClipLoader.onLoadComplete function to recognize the all the data, and not just the last piece of data? Do you know what I'm talking about or do you need more clarification. Thanks for helping me out. I know your time is precious and I really appreciate you spending it on me.
                    • 7. Re: load movie and make clickable
                      kglad Adobe Community Professional & MVP
                      you need to create a persistant variable that will store the value of itemLink. if _root[imageLinkName] is a movieclip you can use _root[imageLinkName].itemLink = itemLink to store the value. the code below will probably work, but you'll need to add [ i ] in the correct locations because this forum interprets that as encoding for italic font and ruins your code. i just copied and corrected your ruined code and made no attempt to add [ i ] in the correct location(s).
                      • 8. Re: load movie and make clickable
                        codescodescodes Level 1
                        YOUR A GENIUS!!!! Thank you so much. I haven't tested out your advice but by looking at it I already know it's going to work. I've coded something similar to that before. I don't know why I didn't think of that now. That deserves three bangs on the head with the door. So disappointed in myself. Anyways, again really appreciate you taking the time to help a total stranger. Good days ahead to you.
                        • 9. Re: load movie and make clickable
                          kglad Adobe Community Professional & MVP
                          you're welcome.