Pavel Severýn
Pavel Severýn

Reputation: 255

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-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

Upvotes: 1

Views: 480

Answers (3)

Tahir Alvi
Tahir Alvi

Reputation: 994

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 .

Upvotes: 1

Yordan Yanakiev
Yordan Yanakiev

Reputation: 2604

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.

Upvotes: 1

dain
dain

Reputation: 6699

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.

Upvotes: 1

Related Questions