С гибкой структурой приходит класс "Singleton", который позволяет
зарегистрировать класс к интерфейсу.
С помощью этого метода вы можете скрыть любые функции, которые вы хотите просто не включить его в интерфейсе
// USAGE: is as simple as importing the class and then calling the
// method you want.
import com.samples.Sample
// and then simple just doing
trace(Sample.someFunction()) // will return true
// Sample.as
package com.samples{
import flash.utils.getDefinitionByName;
import mx.core.Singleton;
public class Sample{
//private static var implClassDependency:SampleImpl;
private static var _impl:ISample;
// static methods will call this to return the one instance registered
private static function get impl():ISample{
if (!_impl) {
trace('registering Singleton Sample')
Singleton.registerClass("com.samples::ISample",com.samples.SampleImpl);
_impl = ISample(Singleton.getInstance("com.samples::ISample"));
}
return _impl;
}
public static function someFunction():Boolean {
return impl.someFunction( )
}
}
}
// ISample.as
package com.samples{
public interface ISample {
function someFunction():Boolean;
}
}
// SampleImpl.as
package com.samples{
// ExcludeClass will hide functions from the IDE
[ExcludeClass]
// we can extends a class here if we need
public class SampleImpl implements ISample{
// the docs say we need to include this but I donno about that
// include "../core/Version.as";
public function SampleImpl(){
// call super if we are extending a class
// super();
}
// instance will be called automatically because we are
// registered as a singleton
private static var instance:ISample;
public static function getInstance():ISample{
if (!instance)
instance = new SampleImpl()
return instance;
}
}
// public functions where we do all our code
public function someFunction():Boolean {
return true;
}
}
Просто FYI см: http://stackoverflow.com/questions/137975/what -is-так плохо-о-Singletons. Существует почти всегда лучший способ. –