简体   繁体   English

在较大的项目中使用单独的.fla文件作为MovieClip

[英]Using a separate .fla file as a MovieClip in a larger project

Just to preface: I haven't used Flash in a long long time, however, I am still aware of the environment. 只是作为序言:我已经很长时间没有使用Flash了,但是我仍然知道环境。

Backstory: I created a small .fla to perform actions on a MovieClip on the stage (in my case, a health/HP bar). 背景故事:我创建了一个小的.fla,以便在舞台上的MovieClip上执行操作(在我的情况下,是健康/ HP栏)。 I made the health effect using a Document Class (HealthBar.as). 我使用文档类(HealthBar.as)产生了健康效果。

The question: What I'm trying to figure out now is how, in a totally separate .fla, to create multiple instances of these health bars and be able to access the methods in Document Class HealthBar.as from the Document Class in this new .fla 问题:我现在要弄清楚的是,如何在一个完全独立的.fla中,创建这些运行状况栏的多个实例,并能够在此新版本的Document Class中访问Document Class HealthBar.as中的方法。 .fla

If I am doing this incorrectly in the first place, feel free to yell at me, and let me know how doing something like this SHOULD have been done. 如果我一开始做错了,请大吼大叫我,让我知道该做些什么。

Thanks for any help 谢谢你的帮助

Shouldn't you be able to copy the movieclip from the healthbar .fla into your main .fla and then give it an actionscript linkage of HealthBar? 您是否应该能够将影片剪辑从healthbar .fla复制到主.fla中,然后为其提供HealthBar的动作脚本链接?

Then you should be able to call new HealthBar whenever you need one in your main file. 然后,只要您在主文件中需要一个新的HealthBar,便应该能够调用它。

You're halfway there with a document class. 您正在学习文档类。 Now you just need to make it into a proper class in your com.domain.className (or drop the .as file into the same directory as your fla). 现在,您只需将其放入com.domain.className中的适当类中(或将.as文件放入与fla相同的目录中)。 While creating classfiles is trivial, online examples seem to muck it up, so here's Adobe's official demo ( bleh ). 虽然创建类文件很简单,但在线示例似乎使它变得糟透了 ,所以这里是Adobe的官方演示bleh )。

That said, creating more healthbars basically looks like this... 也就是说,创建更多的Healthbars基本上是这样的...

Class

package {
    public class HealthBar extends Sprite {
        public function HealthBar() {
            // constructor
            trace("Healthbar created")
        }
    }
}

Document Code 文件编号

import HealthBar;

for (var i:int = 0; i < 10; i++) {
    var randomHealthBar:HealthBar = new HealthBar(); // <-- magic sauce
    addChild(randomHealthBar);
}

// traces: "Healthbar created" 10 times

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM