从类方法内部添加 MovieClip

发布于 2024-09-05 22:13:04 字数 871 浏览 7 评论 0原文

我一直在尝试从类中将影片剪辑添加到我的 .fla 文件中。

我的主 fla 文件:main.fla 动作脚本文件:script.因为

它们位于同一目录中。

script.as 文件如下:

package  {
import flash.display.*

public class MyClass extends MovieClip
{
    public var target:MovieClip;

    public function MyClass() 
    { 
        init();

    }

    public function init() //if this method will be runed only inside class it should be private not public
    {
        trace('created');

    }
    public function create()
    {
        target = new myfan();
        target.x = 400;
        target.y = 50;
        stage.addChild(target);


    }
}

}

我使用 create 函数从 main.fla 文件创建添加影片剪辑。

var trying:MyClass = new MyClass();
trying.create();

输出给出“已创建”,但我在输出的 swf 文件中看不到“myfan”影片剪辑。

我一整天都在寻找,但找不到太多。

如何从类文件添加影片剪辑?

感谢您的热心帮助。

I have been trying to add a movieclip to my .fla file from a class.

my main fla file: main.fla
actionscript file: script.as

they stay in the same directory.

script.as file as follows:

package  {
import flash.display.*

public class MyClass extends MovieClip
{
    public var target:MovieClip;

    public function MyClass() 
    { 
        init();

    }

    public function init() //if this method will be runed only inside class it should be private not public
    {
        trace('created');

    }
    public function create()
    {
        target = new myfan();
        target.x = 400;
        target.y = 50;
        stage.addChild(target);


    }
}

}

I use create function to create add the movieclip from main.fla file.

var trying:MyClass = new MyClass();
trying.create();

The output give "created" but i connot see "myfan" movieclip inside the outputted swf file.

I have been searching all the day but could not find very much.

How can i add a movieclip from a class file?

Thanks for your kind help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁杀 2024-09-12 22:13:04

我对如何将 script.as 附加到 swf 感到有点困惑。 AS3 中的类必须位于与类名完全相同的文件中 - 因此您的文件首先应命名为 MyClass.as。

第二个问题是 myfan 到底是什么?它是你图书馆里的一个符号吗?该符号包含什么?如果将元件拖到舞台上而不是尝试使用 ActionScript 实例化它,会发生什么情况?

最后,如果您要实例化 MyClass 您在哪里这样做?在时间线内电影的第一帧上?我注意到您在任何时候都没有将变量 trying 添加到显示列表中......这意味着变量 stage 可能为空。尝试添加:

public function create()
{
    target = new myfan();
    target.x = 400;
    target.y = 50;
    trace("Stage here?:", stage);
    stage.addChild(target);
}

看看你是否得到了什么。

I'm a bit confused as to how you are attaching the script.as to the swf. Classes in AS3 must be in a file with the exact same name as the class name - so your file should be named MyClass.as as a first point.

The second question is what is myfan exactly? Is it a symbol in your library? What does that symbol contain? What happens if you drag the symbol onto the stage instead of trying to instantiate it using ActionScript?

Finally, if you are instantiating MyClass where are you doing so? On the first frame of the movie within the timeline? I notice that you aren't adding the variable trying onto the display list at any time .... that would mean the variable stage might be null. Try adding:

public function create()
{
    target = new myfan();
    target.x = 400;
    target.y = 50;
    trace("Stage here?:", stage);
    stage.addChild(target);
}

To see if you get anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文