actionscript-3 - 没有类定义的Flash文件是如何编译的?

标签 actionscript-3 flash

让我们使用this第一部分中的代码网站。我没有看到类声明,并且我的程序无法在 FlashDevelop 中构建。我收到以下错误消息:

Error: A file found in a source-path must have an externally visible definition. If a definition in the file is meant to be externally visible, please put the definition in a package.
Build halted with errors (fcsh).

我应该做什么才能构建和运行它?

最佳答案

如果您使用 Flash 开发和纯 AS3(无 Flex),那么所有内容都必须位于类和包中。

只需将该代码包装在自定义类中即可在 flashDevelop 中使用它。如果您在 flash 开发中创建一个新项目,大多数模板都会创建一个 Main.as 文件 - 这是项目加载时运行的根类,只需将代码转储到该 .AS 文件中定义的 Main 类中即可(除了导入,它们需要位于包和类声明之间)。

package {

    //imports here

    public class Main extends MovieClip {
       //put any vars that aren't in functions here  (eg. var mFileReference:FileReference)
       public function Main():void {
           //put anything not contained in a function here
       }

       //put the functions here

    }

}

关于actionscript-3 - 没有类定义的Flash文件是如何编译的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12060555/

相关文章:

java - 数组组合的子集 - AS3

arrays - 我可以在 AS3 中操作多个类中的单个数组吗?

flash - 加载的 swf 中的辅助功能属性未更新

actionscript-3 - 针对SoundEvent修复Flash错误1046

flash - Actionscript 3 mouseover passthrough(忽略鼠标事件)

actionscript-3 - AS3 Flex 中的排序对象/ map ?

actionscript-3 - as3 : Mute button and volume slider on one sound channel

flash - 访问相机

flash - 参数错误 : Error #2015: Invalid BitmapData

flash - 从 Photoshop 到 Flash 具有透明度的 PNG : how to make . swf 显示 .psd 究竟是做什么的?