Results 1 to 4 of 4

Thread: Why Doesn't This Work... Targetting An MC Inside MC

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why Doesn't This Work... Targetting An MC Inside MC

    Inside my mc btn1 I have another mc called 'arrows' but when I target it nothing happens, it's meant to fade _alpha to 0... Any ideas?

    Code:
    for (i=0; i<numOfBtn+1; i++) {
    	this["btn"+i].num = i;
    this["btn"+i].onRollOver = function() {
    		this.play();
    		this.arrows.alphaTo("0", .5, "easeOutQuad", 0);
    	};

  2. #2
    Join Date
    Apr 2007
    Location
    Phoenix, AZ
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've found that using the "this" keyword too much can get you into trouble. I'm guessing that it's not referencing the right mc when you're using it inside your function. You can find out by adding this line to your onRollOver function (you probably already know how to do this):

    trace(this);
    I would actually rewrite your loop to reference the correct movieclip only once, and then you know you've always got the right one:

    Code:
    for (i=0; i<numOfBtn+1; i++) {
    	var my_mc:Movieclip = this["btn"+i];
    	my_mc.num = i;
    my_mc.onRollOver = function() {
    		my_mc.play();
    		my_mc.arrows.alphaTo("0", .5, "easeOutQuad", 0);
    	}
    }
    If that doesn't work, I'd run some more trace actions to see what you're actually referencing. You might also check the syntax of your "alphaTo" function, etc.

  3. #3
    Join Date
    Jan 2007
    Location
    Charlotte, NC
    Posts
    82
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Looks like it's a problem with the for loop. I'm not even sure why you have the my_mc.num = i in there.

    This is how I would write it:
    Code:
    for(var i = 0; i<=numOfBtn; i++) {
         var my_mc = this["btn"+i];
         my_mc.onRollOver = function() {
              this.play();
              this.arrows.alphaTo("0", .5, "easeOutQuad", 0);
         }
    }
    It also might just be a referencing problem because you reference my_mc inside my_mc when it should simply be "this." Hope this helps.

  4. #4
    Join Date
    Apr 2007
    Location
    Phoenix, AZ
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Since the variable my_mc is defined in the same space as the onRollover function, references within the function will refer back to it. It could just be "this", but like I said I try to avoid using the "this" keyword unless I have to. It seems to usually just cause headaches.

    I only included the my_mc.num = i code because it was in the original code by tomyknoker. It may be a variable that's referenced somewhere else in the movie.

    I never heard whether my code fixed the problem or not though.

Bookmarks

Posting Permissions

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