use actionscript file in flex library

穿精又带淫゛_ 提交于 2019-12-10 11:44:28

问题



i want make own flex library and in this library use own actionscript file which will i use in more component in this library..this file contents eg only code

public function computeSum(a:Number, b:Number):Number {
    return a + b;
}

but when i can this create just when i click File-New-Actionscript File (filename - OK) is in Problem view Error: A file found in a source-path must have an externally visible definition. If a definition in the file is meant to be externally visible, please put the definition in a package

thanks for help


回答1:


You should encapsulate it on class, in order to use it with import directive, else u could use it with include

Another approach is to create a "helper" class, or so called "singleton" class. - a class having only 1 instance, created statically. on this class u can expose the library functions which u do need and use them everywhere.

package
{
    public class Singleton
    {
        private static var singleton : Singleton

        public static function getInstance() : Singleton
        {
            if ( singleton == null )
                singleton = new Singleton();
        return singleton;
        }

        public function Singleton()
        {
        }


            public function visibleTroughtTheSingletonfunction( arg1 : int ... ) : void
            {
            }

            public static function directlyVisiable() : void
            {
            }
      }
}

the accessing the singleton would be something like :

Singleton.getInstance.visibleTroughtTheSingletonfunction( 1 );

OR

Singleton.directlyVisiable();

depending on your needs.




回答2:


Well first you'll need to create a class (and a package) and put that method inside that (not just into an empty AS file) and second if you want to be able to access the method without creating an instance of the class make this method static.




回答3:


If you don't need to change the class file during runtime then make action class compile into swc library.

create a Action script project and compile it in the bin folder you found the .swc library file. include that .swc into your project .



来源:https://stackoverflow.com/questions/6198245/use-actionscript-file-in-flex-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!