A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Clickable Movies within Scrollpanes

  1. #1
    Member
    Join Date
    Oct 2003
    Location
    Cincinnati, OH, USA
    Posts
    44

    Clickable Movies within Scrollpanes

    I have written an the following code that dynamically loads a bunch of movies into a Scrollpane. I had a question about the "click-ability" of the movieclips loaded into the scrollpane. Is it possible to attach a variable to the movieclip after it is created, and then reference that variable when the movieclip is clicked? Below is sample code of what I would like to do, but is not working:

    Code:
    var ScrollPane = _root.skin.Explorer.ScrollPane;
    var GalleryMC = ScrollPane.content.createEmptyMovieClip("Gallery"+Gallery.id, 1);
    
    for (var i = 0; i < Gallery.images.length; ++i) {
         var Image = new Object();
         
         Image.name = Gallery.images[i].name;
         Image.width = Gallery.images[i].width;
         Image.height = Gallery.images[i].height;
         
         
         var ImageMC = GalleryMC.createEmptyMovieClip("Pic"+i, i);
         // NOTE THE FOLLOWING LINE:
         ImageMC._ImageName = Image.name;
         
         var PicLoader = new MovieClipLoader();
         PicLoader.onLoadInit = function (targetMC) {
              // NOTE THE FOLLOWING LINE:
              targetMC.onRelease = function() { alert(targetMC._ImageName); };
              ScrollPane.invalidate();
         }
         PicLoader.loadClip(Gallery.path+"/"+Image.name.split(".jpg").join("_thumb.jpg"), ImageMC);
    }

    Although all of the individual movieclips inside of the Scrollpane are click-able, the problem is that ALL of them are sending the Image.name value of the LAST LOADED ImageMC instance to the alert() function when clicked. Any ideas?

    Thanks in advance,
    Aaron

  2. #2
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    targetMC.onRelease = function() { alert(targetMC._ImageName); };

    replace with

    targetMC.onRelease = function() { alert(this._ImageName); };

    give it a try

  3. #3
    Member
    Join Date
    Oct 2003
    Location
    Cincinnati, OH, USA
    Posts
    44
    No luck, when I change it, the value on click is "undefined". I am guessing because "this" is referencing the PicLoader object, not the TargetMC.

    Any other ideas?

  4. #4
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    Well normaly if you declare a onRelease function while in the {} your in the movie. And since TargetMc is from loadInit it does not exist anymore when you click or refer to the last Image create.

    use this to know what's in there put that in the onRelease function

    for(var i in this)
    {
    trace(i + " = " + this[i])
    }

  5. #5
    Member
    Join Date
    Oct 2003
    Location
    Cincinnati, OH, USA
    Posts
    44
    Code:
    PicLoader.onLoadInit = function(targetMC) {
    	for(var i in this)
    	{
    		trace(i + " = " + this[i])
    	}
    	targetMC.onRelease = function() { alert(this._ImageName); };
    	ScrollPane.invalidate();
    }
    Output:
    onLoadInit = [type Function]
    onLoadInit = [type Function]
    onLoadInit = [type Function]
    onLoadInit = [type Function]
    onLoadInit = [type Function]
    onLoadInit = [type Function]
    onLoadInit = [type Function]
    onLoadInit = [type Function]

  6. #6
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    code:

    PicLoader.onLoadInit = function(targetMC) {
    targetMC.onRelease = function() {
    for(var i in this)
    {
    trace(i + " = " + this[i])
    }
    alert(this._ImageName);
    };
    ScrollPane.invalidate();
    }



    Like this

  7. #7
    Member
    Join Date
    Oct 2003
    Location
    Cincinnati, OH, USA
    Posts
    44
    I tried that as well, same output.
    When one of the MCs is clicked, trace ouputs:
    onLoadInit = [type Function]

  8. #8
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    you are suppose to get the output on click right?

  9. #9
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    Well i'm bafled how could the only thing you have in your movie is a function loadInit... Can you send a fla....

  10. #10
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    wait i will try something

  11. #11
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    Code:
    this["PicLoader" + i] = new MovieClipLoader();
         this["PicLoader" + i].onLoadInit = function (targetMC) {
              // NOTE THE FOLLOWING LINE:
              targetMC.onRelease = function() { alert(this._ImageName); };
              ScrollPane.invalidate();
         }
         this["PicLoader" + i].loadClip(Gallery.path+"/"+Image.name.split(".jpg").join("_thumb.jpg"), ImageMC);

  12. #12
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    that make sense since the loop don't wait for the init and replace the picLoader

    Sory i did not see that before

  13. #13
    Member
    Join Date
    Oct 2003
    Location
    Cincinnati, OH, USA
    Posts
    44
    Unfortunately, that didn't work either. I just get "undefined" when any clip is clicked. However, I tried using the built in variable _name (instance name of the movie clip) and it worked - I got the unique instance name of the movieclip that was clicked:

    Code:
    PicLoader.onLoadInit = function(targetMC) {
    	targetMC.onRelease = function() {
    		trace(this._name); 
    	};
    	ScrollPane.invalidate();
    }
    		PicLoader.loadClip(Gallery.path+"/"+Image.name.split(".jpg").join("_thumb.jpg"), ImageMC);
    So perhaps it had something to do with my custom variable.

    Trionik, I absolutely appreciate your help and advice! I think you answered one of my other posts as well - at this rate I should just put you on our payroll!

  14. #14
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    After a few test and some head scratching i found out that when you load the clip everything is erase all variables are gone. It's the same if you are trying to put something in the movieClipLoader object. But there is a way to counter that by using a listener. I have built this to make my test and it's working.

    Have a look at the fla
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center