Actionscript 3 AS3:如何在命名空间中引用函数?
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
// 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关于命名空间的文章说:找不到命名空间或命名空间不是编译时常量。