本文介绍了使用Flex库ActionScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想使自己的Flex库并在该库使用,将我在更多的组件使用自己的ActionScript文件在此library..this文件内容,例如只有code


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

但是当我可以在此创建只是当我点击文件 - 新建 - ActionScript文件(文件名 - OK)是在问题视图错误:在源路径中的文件必须有一个外部可见的定义。如果文件中的定义,就是要外部可见,请把定义在包中

感谢帮助

推荐答案

您应该封装它的类,以便将其用于进口指令,否则ü可以使用它与包括

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

另一种方法是创建一个助手类,或者所谓的单级。 - 一类只具有1个实例,静态创建。这个类U可以揭露其中U确实需要,并利用它们无处不在的库函数。

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

Singleton.directlyVisiable();

根据您的需求。

depending on your needs.

这篇关于使用Flex库ActionScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:38