views:

1954

answers:

1

I have a Flash website template (four pages) that I made using AS 3.0 and Flash CS4. It is for an assignment involving movie clips. Currently on the main time line there is only one frame, and three layers: actions/menu/content.

The actionscript on the main time line is simply:

content_mc.stop ();

There is a movie clip on the stage called “Content” that contains the content for each of the pages.

Inside of that there is a “Menu” movie clip that contains and controls all of the navigation buttons. The actionscript for the Menu movie clip is:

function homeBtnPress (event:MouseEvent):void{
//comments here
//comments here
MovieClip(parent).content_mc.gotoAndStop("home");
}


function aboutBtnPress (event:MouseEvent): void{
MovieClip(parent).content_mc.gotoAndStop ("about");
}

function servicesBtnPress (event:MouseEvent): void{
MovieClip (parent).content_mc.gotoAndStop ("services");


}

function contactBtnPress (event:MouseEvent): void{
MovieClip (parent).content_mc.gotoAndStop ("contact");
}

function portfolioBtnPress (event:MouseEvent): void{
MovieClip (parent).content_mc.gotoAndStop ("portfolio");

}

home.addEventListener(MouseEvent.CLICK, homeBtnPress);
about.addEventListener(MouseEvent.CLICK, aboutBtnPress);
services.addEventListener(MouseEvent.CLICK, servicesBtnPress);
contact.addEventListener(MouseEvent.CLICK, contactBtnPress);
portfolio.addEventListener(MouseEvent.CLICK, portfolioBtnPress);

So everything works fine, but my instructor wants me to control the menu/content from the main time line by using the target path tool. What exactly would I target – just the “menu” and “content” movie clips, and what code would I use? Sorry if I'm not explaining very well, I'm pretty confused.

Here is the feedback from my instructor:

“While we learned how to control the main timeline and the timeline of another movie clip from within a movie clip, this is not the most intuitive way to script and makes for difficult debugging. So you will need to explore how to target your buttons inside of your menu movie clip and the frames within the content movie clip from the main timeline. “

Thanks so much in advance!

A: 

This is a very basic, but handy task.

Have a look here and here to get the idea. The second tutorial uses actionscript 2, but the idea is the same. Do a test, go in the main timeline, to the ActionsPanel, choose insert target path and select a menu clip. do the same from inside conent_mc and see how the path is different. Try to get an idea of how you can access your clips ( much like folders on your file system).

Your tutor is right:

  1. If you have code all over the place ( in many movie clips ) and new need to revisit this project in about a month you will have fogotten where all the code for all the intricate movement of menus/content is and waste time and energy.
  2. Copy/paste code is good to get things going, but as as soon as they do work, and you understood how, try to write it in a manner that makes it easy to modify without having to change to much of your code.

That code, written in the main timeline would maybe look like this:

//setup menu click handlers

content_mc.home.addEventListener(MouseEvent.CLICK, menuPress);
content_mc.about.addEventListener(MouseEvent.CLICK, menuPress);
content_mc.services.addEventListener(MouseEvent.CLICK, menuPress);
content_mc.contact.addEventListener(MouseEvent.CLICK, menuPress);
content_mc.portfolio.addEventListener(MouseEvent.CLICK, menuPress);
//take advantage of the fact that your button name is the same as the frame label in content_mc
function menuPress(event:MouseEvent):void{
   content_mc.gotoAndStop(event.currentTarget.name);
}

I have used currentTarget because that returns the object that was clicked, not some child, depending on mouseChildren being true/false and event bubbling, which is something you might want to have a look at later.

George Profenza