I\'m doing a flash project but I\'m new to actionscript. I have a menu in the main page and I want to make other pages appear when I click on menu items.
I know how to
Loading MovieClip from library:
var mc:MovieClip = new MyClipID();
parentLayer.addChild(mc); // parentLayer can be any DisplayObjectContainer, even the stage
Positioning a loaded clip:
mc.x = 15;
mc.y = 30;
Removing a loaded clip:
if(mc.parent)
{
mc.parent.removeChild(mc);
}
Placing a clip at a specific "layer" (index):
parentLayer.addChildAt(mc, 0); // this will place it behind everything on parentLayer
UPDATE: To answer your latest question, yes, you should remove the previously loaded clip before adding a new one. Then, when you want to display the main image again, you can just remove the currently loaded clip.
UPDATE2: An example of keeping track which page is currently loaded and removing it before displaying a new page:
import flash.display.MovieClip;
import flash.display.DisplayObject;
var currentPage:DisplayObject;
btn_msg.addEventListener(MouseEvent.CLICK, ShowMessagePage);
btn_msg2.addEventListener(MouseEvent.CLICK, ShowMesssagePage2);
function ShowMessagePage(event:MouseEvent):void
{
removeCurrentPage(); // remove the old page
var msg_page:MessagePage = new MessagePage();
addChild(msg_page);
msg_page.x = 495;
msg_page.y = 323;
currentPage = msg_page; // keep track of the current page
}
function ShowMessagePage2(event:MouseEvent):void
{
removeCurrentPage(); // remove the old page
var msg_page2:MessagePage2 = new MessagePage2();
addChild(msg_page2);
msg_page2.x = 495;
msg_page2.y = 323;
currentPage = msg_page2; // keep track of the current page
}
function removeCurrentPage():void
{
if(currentPage && currenPage.parent)
{
currentPage.parent.removeChild(currentPage);
}
}