I've built these website menu buttons and used some ActionScript 2.0 code i ran through in a tutorial on MovieClip Buttons. Trouble is, I need to adjust the AS to link the buttons (on click) to load external movieclips which contain galleries and another menu. With the AS code i've got, it links to the last external movieclip specified in my "if else" statements for each of the 3 buttons - i need it to link to only the external movieclip that corresponds to the button that is currently selected. I think there's something I'm missing. Here is the full code. The section i'm concerned about is the Bolded "doClick function" text below that contains the code I'm unsure about. Any help is appreciated. Thanks.

var groupinfo:Array = [button_Ad, button_Website, button_Logo];

// create constants to define start and stop of fadein and fadeout sequences
// (fadeout should be exactly the same sequence as fadein, in reverse frame order)
var FADEINSTART:Number = 3;
var FADEINSTOP:Number = 9;
var FADEOUTSTART:Number = 10;
var FADEOUTSTOP:Number = 16;

// create a variable to track the currently selected button
var activebtn:MovieClip;

activebtn=button_Ad

// doRollOver: start the rollover action or process, 
// unless the button is currently selected
function doRollOver() {
   if (this != activebtn) {
      // if fading out, send to corresponding frame in fadein
	  if (this._currentframe > FADEOUTSTART && this._currentframe < FADEOUTSTOP) {
         this.gotoAndPlay(FADEINSTART + FADEOUTSTOP - this._currentframe)
      } else {
         this.gotoAndPlay(FADEINSTART);
      } 
   }
}

// doRollOut: start the rollout action or process, 
// unless the button is currently selected
function doRollOut() {
   if (this != activebtn) {
      // if fading in, send to corresponding frame in fadeout
	  if (this._currentframe > FADEINSTART && this._currentframe < FADEINSTOP) {
         this.gotoAndPlay(FADEOUTSTART + FADEINSTOP - this._currentframe);
      } else {
         this.gotoAndPlay(FADEOUTSTART);
      } 
   } 
}	

// doClick: 1) save a reference to previously active button, 2) update activebtn, 
// 3) turn off previously active, 4) turn on current active
function doClick() {
   var prevbtn:MovieClip= activebtn;
   activebtn = this;                       // update pointer to current selection   
   prevbtn.onRollOut();                    // return previously selected to normal
   this.gotoAndStop(1); 
  [B]if(this= button_Ad) {
	secondaryMenu_mc!='ImageGallery_WebAndPrint_FlashMenu.swf';
	secondaryMenu_mc.loadMovie('ImageGallery_WebAndPrint_FlashMenu.swf');
	} else
	if(this= button_Website) {
	  secondaryMenu_mc!='ImageGallery_WebAndPrint_GIFMenu.swf';
	  secondaryMenu_mc.loadMovie('ImageGallery_WebAndPrint_GIFMenu.swf');
	} else
	if(this= button_Logo) {
	  secondaryMenu_mc!=('ImageGallery_WebAndPrint_GIFMenu2.swf');
	  secondaryMenu_mc.loadMovie('ImageGallery_WebAndPrint_GIFMenu2.swf');
	} 
   }[/B]

// assign functions to each event for each button in the group
function init() {
   for (var mc in groupinfo) {  
      groupinfo[mc].onRollOver = doRollOver;
      groupinfo[mc].onRollOut = doRollOut;
      groupinfo[mc].onRelease = doClick;
   }
}



init();

Recommended Answers

All 6 Replies

In the highlighted 'if..else if..' block of code, you need to be using the equality operator == rather than the assignment operator.
e.g.

if(this==button_Ad){
	secondaryMenu_mc.loadMovie('ImageGallery_WebAndPrint_FlashMenu.swf');
	} else
	if(this==button_Website) {
	  secondaryMenu_mc.loadMovie('ImageGallery_WebAndPrint_GIFMenu.swf');
	} else
	if(this==button_Logo) {
	  secondaryMenu_mc.loadMovie('ImageGallery_WebAndPrint_GIFMenu2.swf');
	} 
   }

This might work depending on how you've done things in your fla!
I'm not sure what you're trying to achieve with the lines that were like this:

secondaryMenu_mc!='ImageGallery_WebAndPrint_FlashMenu.swf';

I could be mistaken, but those lines just look completely wrong!

Otherwise, if the first method does not work, and as long as button_Ad, button_Website and button_Logo are instance names of objects, you may have to try something like this for each of the if..else conditions:

if(this._name == "button_Ad")
// irrelevant code snipped
else if (this._name == "button_Website")
// irrelevant code snipped
else if (this._name == "button_Logo")
// irrelevant code snipped

Other than that, I'm out of ideas for now!

Hey, thanks a lot JHip! i was starting to wonder if i'd get any replies on here! Anyways, i tried a few more things to get this to work since i posted this issue, and I had the links almost working 100% - but your extra = was what got it working 100%! definitely awesome. i knew it had to be something small, just had no idea what.

What I was trying to accomplish with the 3 code snippets like this:
" secondaryMenu_mc!='ImageGallery_WebAndPrint_FlashMenu.swf'; " was that if the movie currently loaded into " secondaryMenu_mc " is the link the user's selecting, don't reload the page - so essentially do nothing.

No probs! Been a while since I did any AS2.
It's also been a while since I logged in here. Don't seem to get much time to myself nowadays, so I just check in here as and when I can!

Anyway, glad to have helped!

Nice. well, I actually can't seem to get that

secondaryMenu_mc!='ImageGallery_WebAndPrint_FlashMenu.swf';

code working properly. You said it looked completely wrong before? would you have a better way to do what i'm trying to accomplish? any more advice is greatly appreciated.

OK, well if I understand you correctly, you only want to load the clip into secondaryMenu_mc if the clip hasn't already been loaded.
In which case you'll need to use an if statement:

if(secondaryMenu_mc!='ImageGallery_WebAndPrint_FlashMenu.swf')
	secondaryMenu_mc.loadMovie('ImageGallery_WebAndPrint_FlashMenu.swf');

But comparing the movieclip against the physical filename will NOT work at all and I can't think of any movieclip properties that could help with this comparison either!

However, I can see in your handler code that you are storing the previously activated button and the currently active button. In which case, after you've updated the current and previous buttons, you can simply compare 'this' against the previously active button. If they are both the same, then the current button was clicked before, so it is reasonable to assume that the clip is already loaded (or is being loaded), therefore you don't need to do anything more and can exit the function by calling return.
e.g.

function doClick() 
{
	var prevbtn:MovieClip = activebtn;
	activebtn = this;		// update pointer to current selection   
	prevbtn.onRollOut();		// return previously selected to normal
	this.gotoAndStop(1);

	// if 'this' button is the same as 'prevbtn', the correct clip is 
	// already loaded (or perhaps still loading!)
	if(this == prevbtn)		 
		return;		// so simply return!
	else if(this == button_Ad)	// else load the appropriate clip
		secondaryMenu_mc.loadMovie('ImageGallery_WebAndPrint_FlashMenu.swf');
	else if(this == button_Website) 
		secondaryMenu_mc.loadMovie('ImageGallery_WebAndPrint_GIFMenu.swf');
	else if(this == button_Logo)
		secondaryMenu_mc.loadMovie('ImageGallery_WebAndPrint_GIFMenu2.swf');
}

Fingers crossed, that should solve your problem!

Hey man. that worked great! all my menu's are now functioning 100% - too bad i can't send you a beer through the magic of the internets. heh

The only problem i've got now is getting my Flash XML galleries to load in Firefox. They work totally fine in IE, and mostly fine in Chrome, just not at all in FF, but gives no errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.