从AS3库装卸内容 [英] Loading and unloading content from library in AS3

查看:148
本文介绍了从AS3库装卸内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个闪存项目,但我是新来的动作。 我在主页菜单,我想让其他页面出现时,我点击菜单项。

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 load movieclips from library but I don't know how to specify their position on the screen and how to make them appear in a specific layer.

是否需要卸载previous内容时,我点击菜单的另一个项目? 将它们层叠在一起,使程序沉重的,如果我不卸载它们?!

Is it necessary to unload previous content when I click on another item of menu? will they stack on each other and make the program heavy if I don't unload them?!

我添加了一层每个菜单项,并增加了以下code。在他们每个人(每个项目有不同的类):

I've added a layer for each menu item and added the following code in each of them (For every item there is a different class):

import flash.display.MovieClip;

btn_msg.addEventListener(MouseEvent.CLICK, ShowMessegePage);

function ShowMessegePage(event:MouseEvent):void
{
var msg_page:MessegePage = new MessegePage();
    addChild(msg_page);

msg_page.x = 495;
msg_page.y = 323;

}

我已经把一个图像中的第一帧作为主页。然后,我放在不同的层,每层一些按钮。为了加载,而点击每个按钮的网页,我已经添加了上述code。

I have placed an image in the first frame as the main page. Then I placed some buttons each on separate layers. In order to load a page while clicking on each button, I have added the above code.

当我点击按钮A,第一个被加载,当我点击按钮B上,网页B加载等。我怎么能再次看到主页面?我添加了一个按钮,主页面,但由于某种原因,我也不是什么从库中加载它,它是在第一帧,并在加载内容。我的问题是如何才能我删除加载的内容,这样我可以再次看到主页面?我应该删除pviously加载的内容每$ P $当我点击每一个按钮,然后加载新的内容?

When I click on button A, Page A is loaded, when I click on button B, page B is loaded and so on. How can I see the main page again? I have added a button for the main page but for some reason I do not what to load it from library, it is in the first frame and under loaded contents. My question is how can I remove loaded contents so that I can see the main page again? Should I remove every previously loaded content when I click on every button and then load new contents?

推荐答案

从库中加载的MovieClip:

var mc:MovieClip = new MyClipID();
parentLayer.addChild(mc); // parentLayer can be any DisplayObjectContainer, even the stage

定位加载的剪辑:

mc.x = 15;
mc.y = 30;

删除加载的剪辑:

if(mc.parent)
{
    mc.parent.removeChild(mc);
}

放置夹在一个特定的层(指数):

parentLayer.addChildAt(mc, 0); // this will place it behind everything on parentLayer

更新:要回答你的最新的问题,是的,你的添加一个新的人之前应的删除pviously加载的剪辑的$ P $。然后,当你想再次显示主图像,你可以删除当前加载的剪辑。

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:保持这页是当前加载的曲目,并显示一个新的页面之前取出的一个例子:

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);
    }
}

这篇关于从AS3库装卸内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆