在 flex 库中使用 actionscript 文件 [英] use actionscript file in flex library
问题描述
我想制作自己的 flex 库,在这个库中使用自己的 actionscript 文件,我将在这个库中的更多组件中使用它..这个文件内容,例如只有代码
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;
}
但是当我单击 File-New-Actionscript 文件(文件名 - 确定)时,我可以创建该文件(文件名 - 确定)在问题视图中错误:在源路径中找到的文件必须具有外部可见的定义.如果文件中的定义是外部可见的,请将定义放入包中
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
感谢帮助
推荐答案
你应该将它封装在 class 中,以便与 import
指令一起使用,否则你可以将它与 include 一起使用
You should encapsulate it on class, in order to use it with import
directive, else u could use it with include
另一种方法是创建一个helper"类,或者所谓的singleton"类.- 一个只有 1 个实例的类,静态创建.在这个类上,你可以公开你确实需要的库函数并在任何地方使用它们.
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
{
}
}
}
访问单例将类似于:
Singleton.getInstance.visibleTroughtTheSingletonfunction( 1 );
或
Singleton.directlyVisiable();
取决于您的需求.
这篇关于在 flex 库中使用 actionscript 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!