Groups | Blog | Home
all groups > flash actionscript > june 2005 >

flash actionscript : attaching movie clips to MenuBar menus


pkids
6/28/2005 11:42:54 PM
I'm running MX Pro 2004 on Windows Xp.
I've created a menu bar w/ the MenuBar component, including drop-down menus.
Here's my script for one of the menu items:

var menu = topMenuBar.addMenu("Treatment");
menu.addMenuItem({label:"Bacterial", instanceName:"bacTreatInstance"});
menu.addMenuItem({label:"Viral", instanceName:"viralTreatInstance"});
menu.addMenuItem({label:"Fungal", instanceName:"fungalTreatInstance"});
menu.addMenuItem({label:"Other", instanceName:"otherTreatInstance"});

Now I want to tell those menu items to load a SWF into holder_mc, my empty
movie clip on the stage. I know how to do this using Behaviors, but in
ActionScript, I don't know how to do this. I've searched for info on this
(code, or a tutorial) in several places but can't find it. Would appreciate
direction on this issue. Thanks!
.:}x-=V!P=-x{:.
6/29/2005 8:42:12 PM
pkids
6/29/2005 11:43:00 PM
Thank you for responding! re: exporting for AS, I didn't see where that was an
option. That is, I'm using the MenuBar component, so that's all that's in my
Library. I assumed the instances were named since they are given instance names
in the script below. I managed to attach a trace to it so something is working.
I don't understand why I can't find anything to help me w/ this, since the
logical thing a person would do with menu items is cause them to load a webpage
or movie.

I fully admit that I'm a total newbie and that if I were to take the AS class,
I would probably know how to do this. But I'm working for a nonprofit that
doesn't have the funds just yet to send me to the class, so I'm fishing for
*anything* that will help me.

thank you again for responding -- I hope you can point me in the right
direction --
myIP
6/30/2005 12:00:00 AM
The following code should work for you. Put the code in the main TimeLine.
Name your menuBar?s component instance name to ?topMenuBar?. If you are using
a Loader component or a movieClip holder give it an instance name of
?holder_mc?. When the user selects an item from the menuBar, Holder_mc will
load a image that resides in the same directory as the application (the last
case statement has a quote that will load a image from a folder called
?grosspictures?). I have the code set up for a Loader Component. If you are
using a movieClip holder unquote the loadMovie( ) line and quote out or delete
the ContentPath line. Do this for all of the other case statements. I hope
this helps. Post if you need more help.

var menu = topMenuBar.addMenu("Treatment");
menu.addMenuItem({label:"Bacterial", instanceName:"bacTreatInstance"});
menu.addMenuItem({label:"Viral", instanceName:"viralTreatInstance"});
menu.addMenuItem({label:"Fungal", instanceName:"fungalTreatInstance"});
menu.addMenuItem({label:"Other", instanceName:"otherTreatInstance"});

listenerObject = new Object();
listenerObject.change = function(eventObject)
{
switch(eventObject.menuItem.attributes.instanceName)
{
case("bacTreatInstance"):
holder_mc.contentPath = "bacTreatPic.swf"//or it can be a jpg,
"viralTreatPic.jpg"
break;
case("viralTreatInstance"):
holder_mc.contentPath = "viralTreatPic.swf"
//loadMovie("viralTreatPic.jpg", holder_mc);//use this stlye for movieclip
holder(non-component)!!!
break;
case("fungalTreatInstance"):
holder_mc.contentPath =
"fungalTreatPic.swf"//"grosspicutres/fungalTreatPic.swf"
break;
default:
break;
}
}
topMenuBar.addEventListener("change", listenerObject);
pkids
6/30/2005 6:40:40 PM
myIP -- WOW. It worked!!! You are a lifesaver! Not only did it work, but I can
also study the code -- I was happy to see I had been on the right track, but I
had not encountered the "case" keyword before. Our nonprofit has applied for
some funding that, if received, a small portion of it would pay for me to get
ActionScript training. But in the meantime, your help got me over a roadblock
so I can finish our current project. All that to say THANK YOU so very much --
I really appreciate your help!
myIP
6/30/2005 7:29:30 PM
AddThis Social Bookmark Button