如何访问顶级包在ActionScript? [英] How to access top level package in ActionScript?

查看:213
本文介绍了如何访问顶级包在ActionScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问的ActionScript 3.0顶级功能从类矿,其中具有相同名称的符号(跟踪)的最高级别的功能已经被定义:

I would like to access an ActionScript 3.0 top level function from a class of mine, in which a symbol with the same name (trace) as the top level function is already defined:

class A {
  public static function trace():void {
  }
  trace("Test");
}

我想调用全局ActionScript 跟踪函数跟踪(测试),但这是不可能的,因为另一个符号函数轨迹()定义。

I would like to call the global ActionScript trace function with trace("Test"), but this is not possible as another symbol function trace() is defined.

在一个情况下,我想访问外部定义将设在一个包( flash.utils 左右),我可以访问与外部定义 flash.utils [definitionName] ,因为我在这里跟ByteArray的:

In a case where the external definition which I would like to access would be located in a package (flash.utils or so), I could access that external definition with flash.utils.[definitionName], as I do here with ByteArray:

import flash.utils.*;
class ByteArray {
  var data:flash.utils.ByteArray;
}

有没有类似的语法EX pression在ActionScript 3.0,让我来访问跟踪功能,在第一个例子不改变我的类方法的名称跟踪

这是一个假设性的问题,请不要考虑解决方法。我需要解决的问题完全一样问以上。在此先感谢!

This is a hypothetical question, please do not consider workarounds. I need to solve the problem exactly as asked above. Thanks in advance!

推荐答案

跟踪公开命名空间,以便它可以达到要求公共::跟踪,但是这里的问题是,你正在重新定义另一个公开跟踪,所以你不能调用previous之一。

trace is in the public namespace so it could be reached calling public::trace , however here the problem is that you are redefining another public trace, so you can't call the previous one.

你可以做的是:

1 - 如果你的方法跟踪还没有为公开使其受保护的或私有,然后你会能够调用原始跟踪:

1 - if your method trace have not to be public made it protected or private and then you will be able to call the original trace:

public class Main extends Sprite 
{
    protected function trace(...args):void {
        public::trace(args) // access to the public function trace
    }
    public function Main():void 
    {
        trace("hello world")
    }       
}

2 - 如果你不能改变的签名分配原始跟踪到静态无功/常量,所以你可以在以后使用它:

2 - if you can't change the signature assign the original trace into a static var/const so you can use it later :

public class Main extends Sprite 
{
    // here save the original trace function
    private static const _trace:Function = trace

    public function trace(...args):void {
        _trace(args) // call the original trace
    }
    public function Main():void 
    {
        trace("hello world")
    }       
}

这篇关于如何访问顶级包在ActionScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆