How to access top level package in ActionScript?

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

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.

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

Is there a similar syntactical expression in ActionScript 3.0 that would allow me to access the trace function in the first example without changing the name of my class method trace?

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

Answers


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.

What you can do is :

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 - 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")
    }       
}

Need Your Help

Databases: column encoding, when is it important?

mysql database character-encoding

We are importing data from .sql script containing UTF-8 encoded data to MySQL database:

Android :How to define dialog fragment that is accessed by multiple activities?

android android-fragments android-activity

I have an Activity1 that shows a custom dialogfragment- ExampleDialog. I have implemented a listener, SubmitDialogListener for the dialogfragment to communicate with the activity using onSubmit(). In

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.