Af开发者_开发百科ter I saw the methods in flash.utils package, I decided to make a try:
// inside file Test.as
package com.tests
{
internal function packageFunction() {
}
}
But I got:
A file found in a source-path 'Test' must have the same name as the class definition inside the file 'packageFunction'.
packageFunction is a function, not a class.. Any idea what is wrong?
--update
For those who don't know what is the "package function" I'm talking about, please, see the flash.util package methods. I can use it like:
flash.utils.getTimer();
Your code is in Test.as. It should be in
com/tests/packageFunction.as
This follows the same rules as "normal" classes. The package and main public symbol name must mach the directory path and the file name.
If your code is in the Test.as class , you already are inside a package and you can't have another package inside or outside a package, what you can do is have another Class outside the package
package com.tests
{
public class Test
{
private var example:ClassExample = new ClassExample();
}
}
//This class is only accessible in the Test class
class ClassExample
{
public function ClassExample()
{
}
}
The example you have given is a misunderstanding of the use of packages. The functions described in the docs are accessible within any package , it doesn't mean you can create a package in an existing class to access these functions.
精彩评论