Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3:如何在命名空间中引用函数?_Actionscript 3_Flash_Actionscript - Fatal编程技术网

Actionscript 3 AS3:如何在命名空间中引用函数?

Actionscript 3 AS3:如何在命名空间中引用函数?,actionscript-3,flash,actionscript,Actionscript 3,Flash,Actionscript,AS3对我来说相当陌生。假设我在一个单独的文件中定义了以下类 // saved as ./test/testing.as package test{ public class testing { public namespace nspc; nspc function hello(){ trace("Hello World"); }; } } 如何调用hello()函数?使用指令: use namespace nspc; va

AS3对我来说相当陌生。假设我在一个单独的文件中定义了以下类

// saved as ./test/testing.as
package test{
   public class testing {
      public namespace nspc;
      nspc function hello(){
         trace("Hello World");
      };
   }
}
如何调用hello()函数?

使用指令:

use namespace nspc;

var test:testing = new testing();
test.hello();

这里的问题是如何定义名称空间

基本上,您可以在as3中使用名称空间,它有3个步骤

定义名称空间

package test
{
    use namespace mynamespace;

    public class Testing
    {
        public function Testing()
        {   

        }

        mynamespace function hello():void //This method belongs to mynamespace
        {
            trace("Hello World");
        };
    }
}
var testing:Testing = new Testing();
testing.mynamespace::hello();
文件名应该是
mynamespace.as
。(应与命名空间名称匹配)

应用名称空间

package test
{
    use namespace mynamespace;

    public class Testing
    {
        public function Testing()
        {   

        }

        mynamespace function hello():void //This method belongs to mynamespace
        {
            trace("Hello World");
        };
    }
}
var testing:Testing = new Testing();
testing.mynamespace::hello();
引用名称空间

package test
{
    use namespace mynamespace;

    public class Testing
    {
        public function Testing()
        {   

        }

        mynamespace function hello():void //This method belongs to mynamespace
        {
            trace("Hello World");
        };
    }
}
var testing:Testing = new Testing();
testing.mynamespace::hello();
(或)


Adobe关于命名空间的文章

说:找不到命名空间或命名空间不是编译时常量。