[thelist] [flash MX question]

Scott Shou scott at firesites.com
Tue Jul 16 12:39:01 CDT 2002


I'm not quite sure if this is the right place to post this question, but
then again, I've seen such a variety of topics covered with great expertise
here, that it doesn't seem completely off topic.

The menu we're trying to write was working but now seems to have stopped
doing the rollover effect.

Basically we're making a movie clip dynamically then adding 2 text fields,
one for the text and one for the shadow.

Can anyone see why there is no reference to the menu property when the
rollover happens?

Any other general comments would be great also.. still experimenting on what
is faster, etc.

Thanks in advance for your help and guidance!


function showProps(obj) {
 tmp = '';

 for (g in obj) {
  tmp += g + ': ' + obj[g] + '\n';
 }
 trace(tmp);
}


// Constructor for the menu object
function Menu (mc,font,size,active,label,top,spacer) {
 this.mc          = mc;
 this.items       = [];
 this.fontFace    = font;
 this.fontSize    = size;
 this.colorActive = active;
 this.colorNormal = label;
 this.top         = top;
 this.spacer      = spacer;
}

Menu.prototype.addItem  = function (item) {
 this.items[this.items.length] = item;
}

Menu.prototype.totalHeight = function () {
 height = 0;
 for (var x=0; x<this.items.length;  x++) {
  height += this.items[x].mc.label.textHeight;
 }
 return height;
}


// Constructor for menu items
function MenuItem(menu,id,label,icon,action,help) {
 this.menu     = menu;
 this.id       = id;
 this.label    = label;
 this.icon     = icon;
 this.action   = action;
 this.help     = help;
 this.assemble();
}

MenuItem.prototype.assemble = function() {
 // Create an empty movie clip, name after array position
 newItem =
this.menu.mc.createEmptyMovieClip('menuItem_'+this.id,this.menu.items.length
);

 // Create the label
 MenuItemText(newItem,'label',this);

 // Create the shadow
 MenuItemText(newItem,'shadow',this);

 // Attach the icon
 newItem.attachMovie(this.icon,'menuicon_' +
this.id,this.menu.items.length+3);
 newItem['menuicon_' + this.id]._x = newItem.shadow._x +
newItem.shadow._width +10

 // Adjust the position
 newItem._y = this.menu.top + this.menu.totalHeight() +
(this.menu.spacer*this.menu.items.length);
 newItem._x = 170

 // Assign the behavior
 newItem.onRollOver = function () {
  //HelpText.text = this.label.text;
  this.label.setTextFormat(new
TextFormat(this.menu.fontFace,this.menu.fontSize,this.menu.colorActive,1,0,0
,null,null,"right"));
 }

 newItem.onRollOut  = function () {
  //HelpText.text = '';
  this.label.setTextFormat(new
TextFormat(this.menu.fontFace,this.menu.fontSize,this.menu.colorNormal,1,0,0
,null,null,"right"));
 }

 // Save the movieclip
 this.mc = newItem;
}

function MenuItemText(newItem,itemType,item) {
 // Setup the variables for the item
 if (itemType == 'label') {
  depth = 1;
  x     = 0;
  y     = 0;
  itemColor = item.menu.colorNormal;
 } else {
  depth = 0;
  x     = 1;
  y     = 1;
  itemColor = '0x000000';
  var extended  = { _alpha:50 }
 }

 // Create the text field
 newItem.createTextField(itemType,depth,x,y,0,0);

 // Add properties
 with (newItem[itemType]) {
  text = item.label;
  autoSize = "right";
  embedFonts = true;
  setTextFormat(new
TextFormat(item.menu.fontFace,item.menu.fontSize,itemColor,1,0,0,null,null,"
right"));
 }

 // Apply extended properties
 if (extended) {
  for (var g in extended) {
   newItem[itemType][g] = extended[g];
  }
 }
}





More information about the thelist mailing list