Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何从Flash AS3.0中的子包类访问默认包中的类_Actionscript 3_Class_Object_Flash Cs5 - Fatal编程技术网

Actionscript 3 如何从Flash AS3.0中的子包类访问默认包中的类

Actionscript 3 如何从Flash AS3.0中的子包类访问默认包中的类,actionscript-3,class,object,flash-cs5,Actionscript 3,Class,Object,Flash Cs5,尝试从默认包中的类的子包中访问该类时,我收到错误消息。谁能帮我解决这个问题吗 仅供参考,我的包结构是A->B。我的意思是文件夹“A”作为默认包,“B”作为子包 提前谢谢 只需创建类a的对象,并从其对象调用类实例方法 var classAObj:A = new A(); classObj.MethodA(); 我认为您正在寻找的是类B扩展类A。在您的代码中类似于这样: package main { class B extends A { // Code here.

尝试从默认包中的类的子包中访问该类时,我收到错误消息。谁能帮我解决这个问题吗

仅供参考,我的包结构是A->B。我的意思是文件夹“A”作为默认包,“B”作为子包


提前谢谢

只需创建类a的对象,并从其对象调用类实例方法

var classAObj:A = new A();
classObj.MethodA();

我认为您正在寻找的是类B扩展类A。在您的代码中类似于这样:

package main
{
    class B extends A
    {
        // Code here...
    }
}

在包中包含代码通常不会影响功能,它更像是一种组织工具。(除了
内部
关键字。)

私有、受保护公共如何?我在其他答案中看不到任何解释,所以就在这里

class A
{
    private var _password:String;
    public var username:String;
    protected var serverURL:String;

    public function login():void
    {
         // some code
         callServerForLogin();
    }

    protected function callServerForLogin():void
    { 
        // some code
    }
 }

 class B extends A
 {
      public function B()
      {
           var parentPassword = super._password;  
           // FAILS because private and accessible only inside class A

           var parentUsername = super.username 
           // all ok in here, public property

           var parentServerURL = super.serverURL;
           // all ok, because it is protected

           // also we can call super.login(); or super.callServerForLogin();

      }

      // IMPORTANT we are also allowed to override public and protected functions
      override public function login():void
      {
          super.login(); 
          // we call the parent function to prevent loosing functionality;  

          Alert.show("Login called from class B");
      }

      override protected function callServerForLogin():void
      {
           super.callServerForLogin();
           // keep also parent logic

           Alert.show("calling protected method from B");
      }
 }


 // ----  Now considering you declare an object of type B you can do the following
 var bObj:B = new B();

 // access public properties and call public functions from both B and A
 bObj.username = "superhero";
 bObj.login();

 // will get compile error for next lines
 bObj.serverURL = "host.port";
 bObj.callServerForLogin();

谢谢你抽出时间。对不起,我在描述我的问题时错了。现在我编辑清楚了。请看你是否能帮我。嗨,我还是不确定我是否明白。你能发一些代码吗?谢谢你的时间。对不起,我在描述我的问题时错了。现在我编辑清楚了。请看看你是否能帮我。谢谢你的时间。对不起,我在描述我的问题时错了。现在我编辑清楚了。请看看你能不能帮我。答案是你不能。这就是为什么在默认包中创建类时,Flash Builder会给您一个警告。