开发者

use actionscript file in flex library

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-pat开发者_JS百科h 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


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.


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.


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 .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜