Reputation: 9279
AS3 is rather new to me. Let's say I have the following class defined in a separate file.
// saved as ./test/testing.as
package test{
public class testing {
public namespace nspc;
nspc function hello(){
trace("Hello World");
};
}
}
How can I call the hello() function?
Upvotes: 0
Views: 264
Reputation: 36237
Problem here is way of define namespace.
Basically you can use the namespace in as3 which have 3 steps.
Defining namespaces
File name should be mynamespace.as
. (Should match with Namespacename)
package test
{
public namespace mynamespace; //Note here no class/interface declaration.
}
Applying namespaces
package test
{
use namespace mynamespace;
public class Testing
{
public function Testing()
{
}
mynamespace function hello():void //This method belongs to mynamespace
{
trace("Hello World");
};
}
}
Referencing namespaces
var testing:Testing = new Testing();
testing.mynamespace::hello();
(or)
use namespace mynamespace;
var testing:Testing = new Testing();
testing.hello();
Adobe article about namespace http://www.adobe.com/devnet/actionscript/learning/as3-fundamentals/namespaces.html
Upvotes: 1
Reputation: 39476
With the use namespace
directive:
use namespace nspc;
var test:testing = new testing();
test.hello();
Upvotes: 0