从 AS3 中的链接类引用实例名称

发布于 2024-11-17 17:23:09 字数 764 浏览 2 评论 0原文

我有一个链接的类,带有一个外部 .as 文件,绑定到一个包含 fla 中名为“Menu”的影片剪辑。在此actionscript 文件中,我尝试从我使用flash 创作工具制作的一些内容中提取一些信息。在我用实例名称“greensboro”和“birmingham”绘制的 fla 舞台上有一些符号,我想在链接类的某些函数中获取它们的 x 位置。我尝试从“greensboro.x”返回一个值,但当然它说变量 greensboro 不存在,因为我没有在类中定义它。当然有某种方法可以在我的链接类的变量中获取该信息!

编辑:这里有一些代码来展示我所尝试的内容(删除其他所有内容)。这是在链接类的 .as 文件中:

package {

    import flash.display.*;
    import flash.net.URLRequest;
    import flash.events.*;
    import flash.net.URLLoader;
    import fl.transitions.Tween;


    public class Menu extends MovieClip {

        public function Menu() {
        trace(birmingham.x);
        }

        public function get birmingham() : MovieClip {
        return root.getChildByName("birmingham") as MovieClip;
        }
    }
}

I've got a linked class, with an external .as file, tied to a movie clip called "Menu" in an encompassing fla. In this actionscript file, I am trying to pull some information from a few things I made with the flash authoring tool. There are a few symbols on stage in the fla that I drew with instance names "greensboro" and "birmingham", and I want to get their x-position inside some functions of the linked class. I've tried returning a value from "greensboro.x" but of course it says the variable greensboro doesn't exist, because I haven't defined it in the class. Surely there is some way of getting that info in a variable of my linked class!

Edit: here is some code to show what I've tried(cutting everything else). This is in the .as file of the linked class:

package {

    import flash.display.*;
    import flash.net.URLRequest;
    import flash.events.*;
    import flash.net.URLLoader;
    import fl.transitions.Tween;


    public class Menu extends MovieClip {

        public function Menu() {
        trace(birmingham.x);
        }

        public function get birmingham() : MovieClip {
        return root.getChildByName("birmingham") as MovieClip;
        }
    }
}

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

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

发布评论

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

评论(3

-残月青衣踏尘吟 2024-11-24 17:23:09

您可以在类中创建一个公共变量,如下所示:

public var birmingham : MovieClip;

然后使用它,或者创建一个像这样的 getter 来读取信息:

public function get birmingham() : MovieClip
{
   return this.getChildByName("birmingham") as MovieClip;
}

在这两种情况下,您应该能够使用 birmingham.x

you can either make a public var inside the class like this:

public var birmingham : MovieClip;

and use it afterwards or create a getter like this to read out information:

public function get birmingham() : MovieClip
{
   return this.getChildByName("birmingham") as MovieClip;
}

in both cases you should be able to use birmingham.x

两仪 2024-11-24 17:23:09
xValue = this['greensboro'].x;

或者

xValue = this['birmingham'].x;
xValue = this['greensboro'].x;

OR

xValue = this['birmingham'].x;
一生独一 2024-11-24 17:23:09

好吧,伙计们。刚刚弄清楚......我在链接的类中使用了 BJornson 的代码,但将 this 替换为 parent。就是这样:

package {

    import flash.display.*;


    public class Menu extends MovieClip {

        public function Menu() {
        trace(birmingham.x);
        }

        public function get birmingham() : MovieClip {
        return parent.getChildByName("birmingham") as MovieClip;
        }
    }
}

就像魔法一样!现在我正在从主 fla 舞台上的 MovieClip 对象中提取 x 值,并将它们返回以在我的链接类中使用!超级有用

Alrighty, dudes. Just figured it out...... I used BJornson's code in the linked class, but replaced this with parent. Here it is:

package {

    import flash.display.*;


    public class Menu extends MovieClip {

        public function Menu() {
        trace(birmingham.x);
        }

        public function get birmingham() : MovieClip {
        return parent.getChildByName("birmingham") as MovieClip;
        }
    }
}

Like magic! now I'm pulling x-value from MovieClip objects on the main fla's stage, and returning them for use inside my linked class! Super useful

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