Script 标记中的代码在生成的 AS 类中位于何处?

发布于 2024-09-03 01:20:13 字数 209 浏览 4 评论 0原文

我想知道 标记中包含的代码会发生什么情况。如果我定义一个函数,它就会成为生成类的成员函数。但我注意到,如果我只在那里编写一些(静态)方法调用(具体来说,我调用 Font.registerFont()),编译器似乎没问题。它工作得很好,但我对这样做感到有点内疚,因为我不知道到底发生了什么以及代码何时执行。

I was wondering what happens to the code contained in an <mx:Script> tag. If I define a function tehre, it just becomes a member function of the generated class. But I noticed that it seems OK for the compiler if I just write some (static) method calls there (specifically, I call Font.registerFont()). It works fine, but I feel kind of guilty for doing this, because I have no idea what's really happening and when the code gets executed.

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

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

发布评论

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

评论(2

沧桑㈠ 2024-09-10 01:20:13

MXML 正式是一种 ActionScript 生成语言。因此,Flex 编译器会将所有 MXML 转换为 ActionScript。

如果你想看看会发生什么;将“keep- generated-actionscript”参数添加到编译器中,然后您可以查看生成的 ActionSCript 代码。

http://livedocs.adobe.com/flex/3/html/ compilers_14.html#157203

除此之外;我不太明白你的问题。为什么静态方法会让你感到内疚?

MXML is formally an ActionScript generation language. So, the Flex compiler will translate all MXML into ActionScript.

If you wan to see what happens; add the 'keep-generated-actionscript' argument to the compiler and then you can look at the generated ActionSCript code.

http://livedocs.adobe.com/flex/3/html/compilers_14.html#157203

Beyond that; I don't really understand your question. Why would static methods make you feel guilty?

神经暖 2024-09-10 01:20:13

遵循的建议www.Flextras.com的回答,我保留了生成的Actionscript类并看了看。 标记内的代码只需按原样放入类主体中。知道了这一点,我可以深入研究 Flex livedocs 并发现有关类定义的部分中的以下段落:

ActionScript 3.0 不仅允许您在类主体中包含定义,还允许包含语句。类体内部但方法定义外部的语句只执行一次——当第一次遇到类定义并创建关联的类对象时。

因此,将语句放入 MXML 文件中的

Following the advice of www.Flextras.com's answer, I kept the generated Actionscript classes and had a look. The code inside <mx:Script> tags is simply put in the class body as-is. Knowing that, I could dig into the Flex livedocs and came across the following paragraph in the section about class definitions:

ActionScript 3.0 allows you to include not only definitions in a class body, but also statements. Statements that are inside a class body, but outside a method definition, are executed exactly once--when the class definition is first encountered and the associated class object is created.

So, putting statements inside a <Script> tag in an MXML file is equivalent to putting code in a static block in a Java class definition.

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