Script 标记中的代码在生成的 AS 类中位于何处?
我想知道
标记中包含的代码会发生什么情况。如果我定义一个函数,它就会成为生成类的成员函数。但我注意到,如果我只在那里编写一些(静态)方法调用(具体来说,我调用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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?
遵循的建议www.Flextras.com的回答,我保留了生成的Actionscript类并看了看。
标记内的代码只需按原样放入类主体中。知道了这一点,我可以深入研究 Flex livedocs 并发现有关类定义的部分中的以下段落:因此,将语句放入 MXML 文件中的
标记内相当于将代码放入 Java 类定义中的
static
块中。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:So, putting statements inside a
<Script>
tag in an MXML file is equivalent to putting code in astatic
block in a Java class definition.