Ultrashock Forums > Flash > ActionScript
Accessing MC after attachMovie

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
Accessing MC after attachMovie
Old 2008-04-12

Accessing MC after attachMovie

Hi all,

This is a simplified version of the script I'm using.

ActionScript Code:
  1. var aNames:Array = ["Bob", "Carl", "Christopher", "Wayne", "Peter"];
  2. for (var i = 0; i<aNames.length; i++) {
  3.     nameBtn = mholder.attachMovie("mbtn", "mbtn"+i, mholder.getNextHighestDepth());
  4.     nameBtn.tTxt.text = aNames[i];
  5.     nameBtn.tTxt.autoSize = "left"
  6.     nameBtn._y = 0;
  7.     //
  8.     //
  9.     if (i != 0) {
  10.         var nameBtnPrev = nameBtn["mbtn"+(i-1)];//trying to get to previous mc
  11.         trace(nameBtnPrev);
  12.         nameBtn._x = nameBtnPrev._x+nameBtnPrev._width+20;
  13.     }
  14.  
  15. }

I'm trying to make a simple horizontal navigation and the buttons which are MCs need to be spaced evenly with the same space inbetween. I'm trying to do it using the previous clips _x and width and then spacing the next clip after that.

The problem is I've forgot (or can't) access the previous clip. I was trying to it this way.

ActionScript Code:
  1. var nameBtnPrev = nameBtn["mbtn"+(i-1)];
postbit arrow 2 comments | 266 views postbit arrow Reply: with Quote   
Registered User
cooper10 is offline
seperator
Posts: 26
2007-12-14
cooper10 lives in United Kingdom
seperator

Ultrashock Member Comments:
ewinter ewinter is offline ewinter lives in Croatia 2008-04-12 #2 Old  
I would simply add an prevBtn = nameBtn; at the end of the for loop.
Reply With Quote  
ewinter ewinter is offline ewinter lives in Croatia 2008-04-12 #3 Old  
Or, fix your code:

Code:
var nameBtnPrev = mholder["mbtn"+(i-1)];
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: