ActionScript Visible Property to Toggle Menu

ActionScript Visible Property to Toggle Menu
In the past few Flash tutorials, we have created the toggle button and the if statement for the Flash Storybook Menu Overlay. As we discussed, the PositionSetMenu function uses the if statement to determine where FlashR will place the Menu Overlay when the toggle button is clicked, depending on the value of the showMenu variable.

function PositionSetMenu(event:MouseEvent):void {

if(showMenu)
{
moveSetMenuDown();
}
else
{
moveSetMenuUp();

}
// Toggle whether you want to load or unload the menu
showMenu = !showMenu;

}

Now we will examine the code for the moveSetMenuDown and moveSetMenuUp functions. Our first step is to discuss the visible property for a movie clip. This property is a Boolean, which means that it has only two values - true and false. As the name indicates, this property determines if the movie clip is visible on the stage. Also, if a movie clip is invisible on the stage, it is disabled and cannot be clicked. We will manipulate this property for each element on the Menu Overlay, which are the background (setMenuBg), button link to the credits page (creditsBtn), toggle button for the background music (musicBtn), button link to the index page (indexBtn), hyperlink to the app's supporting website (websiteBtn) and button link to "our other apps" page (moreAppsBtn).

When we run the moveSetMenuDown function to display the Menu Overlay over the existing page, we will set the visible property for each element to true. Of course, when we run the moveSetMenuUp function, we will set the visible property to false.

You might ask: If we are setting the visibility of the Menu Overlay to false, why do we bother to remove it from the stage. Although it may be invisible on the stage, Flash will still "draw" the Menu Overlay for each frame that it is on the stage. To save on processing during those times when we don't need the menu, we can remove the menu from the stage.

When the app first loads, the Menu Overlay is off the stage. So let's initially set the visible property for each element in the menu to false.

setMenuBg.visible = false;
creditsBtn.visible = false;
musicBtn.visible = false;
indexBtn.visible = false;
websiteBtn.visible = false;
moreAppsBtn.visible = false;

Our next step is to code the moveSetMenuUp function. As you can see from the code below, when this function is called, we will set the X and Y positions and the visible property for each element. We will discuss the removeListeners function in a future tutorial.

function moveSetMenuUp():void {
setMenuBg.x = 0;
setMenuBg.y = -785;
setMenuBg.visible = false;
creditsBtn.x = 486;
creditsBtn.y = -606;
creditsBtn.visible = false;
musicBtn.x = 285;
musicBtn.y = -606;
musicBtn.visible = false;
indexBtn.x = 88;
indexBtn.y = -611;
indexBtn.visible = false;
websiteBtn.x = 340;
websiteBtn.y = -316;
websiteBtn.visible = false;
moreAppsBtn.x = 709;
moreAppsBtn.y = -603;
moreAppsBtn.visible = false;

removeListeners();
}

function moveSetMenuDown():void {
setMenuBg.x = 0;
setMenuBg.y = 0;
setMenuBg.visible = true;
creditsBtn.x = 486;
creditsBtn.y = 178;
creditsBtn.visible = true;
musicBtn.x = 285;
musicBtn.y = 178;
musicBtn.visible = true;
indexBtn.x = 88;
indexBtn.y = 173;
indexBtn.visible = true;
websiteBtn.x = 340;
websiteBtn.y = 468;
websiteBtn.visible = true;
moreAppsBtn.x = 709;
moreAppsBtn.y = 181;
moreAppsBtn.visible = true;

loadListeners();

}

Next →

IMPORTANT: These app development tutorials are written with the Flash novice in mind. You will need to optimize your app beyond what is covered in these tutorials before finalizing your app for the app store.

Copyright 2018 Adobe Systems Incorporated. All rights reserved. Adobe product screen shot(s) reprinted with permission from Adobe Systems Incorporated. Adobe, Photoshop, Photoshop Album, Photoshop Elements, Illustrator, InDesign, GoLive, Acrobat, Cue, Premiere Pro, Premiere Elements, Bridge, After Effects, InCopy, Dreamweaver, Flash, ActionScript, Fireworks, Contribute, Captivate, Flash Catalyst and Flash Paper is/are either [a] registered trademark[s] or a trademark[s] of Adobe Systems Incorporated in the United States and/or other countries.





RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map








Content copyright © 2018 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.