【问题标题】:folder hierarchy in flash cs5.5flash cs5.5中的文件夹层次结构
【发布时间】:2012-11-11 14:47:28
【问题描述】:

我正在尝试在 Flash 中创建文件夹层次结构,我拥有的文件夹是

C:\uk\ac\uwe\webgames\math

在数学文件夹中,我有一个名为 GameMath.as 的文件

package uk.ac.uwe.webgames.math{

    public class GameMath {

// ------- Constructor -------
        public function GameMath() {

        }

// ------- Properties -------

        const PI:Number = Math.PI;


        // ------- Methods -------

public function areaOfCircle(radius:Number):Number {

        var area:Number;
        area = PI * radius * radius;
        return area;

}



    }
}

在 webgames 文件夹中,我有一个名为 webgames_driver.fla 的文件

import uk.ac.uwe.webgames.math.GameMath;
import flash.text.TextField;

// Create a GameMath instance 

var output:TextField = new TextField();


var aGameMathInstance:GameMath = new GameMath();

// you will need to create a dynamic textfield called
// output on the stage to display method return value

output.text=aGameMathInstance.areaOfCircle(5).toString();
addChild(output);

//trace(aGameMathInstance.areaOfCircle(1))

但是我收到以下错误

场景 1,“Layer 1”层,第 1 帧,第 1 行 1172:定义 uk.ac.uwe.webgames.math:找不到GameMath。

场景 1,“Layer 1”层,第 1 帧,第 1 行 1172:定义 uk.ac.uwe.webgames.math:找不到GameMath。

场景 1,图层“图层 1”,第 1 帧,第 5 行 1046:找不到类型或 不是编译时常量:GameMath。

场景 1,“Layer 1”层,第 1 帧,第 5 行 1180:调用可能 未定义的方法 GameMath。

任何人都可以帮助我,因为我只是卡住了,而且我真的是 flash 新手

【问题讨论】:

    标签: flash-cs5


    【解决方案1】:

    我将尽可能用基本和详细的术语来说明这一点,这不仅是为了您的利益,也是为了其他阅读本文但对自定义类没有丰富经验的人。最好现在就把它全部拿出来,避免混淆。 (我知道我希望有人能在我早期的一些问题上给我这么详细的信息……)

    导入代码用于导入 .as 类。如您所知,在一个类的顶部,您会编写类似这样的代码(我自己的自定义类 Trailcrest 除外)。

    package trailcrest
    {
       public class sonus
       {
    

    然后,在我的 .fla 或 .as 文件中,我可以使用

    import trailcrest.sonus;
    

    我会提到您的 .fla 必须位于包含您要导入的所有自定义类的主目录中。我的文件布局是这样的(括号中的文件夹):

    MyProject.fla
    MyDocumentClass.as
    (trailcrest)
       sonus.as
    

    请注意,我的包名称与文件夹结构相对应,其中包含 .fla 的文件夹被代码假定为起始位置。如果我想使用像 trailcrest.v1 这样的包名,文件夹必须是这样的:

    MyProject.fla
    MyDocumentClass.as
    (trailcrest)
       (v1)
          sonus.as
    

    然后,我会使用

    来引用我的自定义类
    import trailcrest.v1.sonus;
    

    请注意,MyProject.fla 必须位于该文件夹结构的主目录中。这是因为 Flash 不能向后搜索文件夹,只能向前搜索。所以如果我有这样的结构......

    (project)
       MyProject.fla
       MyDocumentClass.as
    (trailcrest)
        sonus.as
    

    ...那么,代码行...

    import trailcrest.sonus;
    

    ...将搜索路径“\project\trailcrest\sonus.as”,如您所见,该路径不存在。 Flash 无法转到“\project\”的父文件夹。

    你的代码行...

    import uk.ac.uwe.webgames.math.GameMath;
    

    ...正在寻找路径“webgames\uk\ac\use\webgames\math\GameMath.as”。 (请记住,代码假定包含 .fla 的文件夹作为起始位置,因此代码实际上是在尝试转到“C:\uk\ac\uwe\webgames\uk\ac\use\webgames\math \GameMath.as")

    要解决此问题,您需要更改 GameMath.as 的包:

    package math{
    

    ...以及代码中的导入语句:

    import math.GameMath;
    

    这会将所有内容指向文字路径“C:\uk\ac\uwe\webgames\math\GameMath.as

    我希望这能回答你的问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-03
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      相关资源
      最近更新 更多