Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I came across some other alternatives after all and thought I'd share them here.</p> <h1>Alternative 1 - use inheritence</h1> <p>This is probably an obvious answer, but is limited. You would put your static methods into a parent class, inherit them to get them in the subclasses. This would only work with classes. Also, because ActionScript is single inheritence, you can only inherit once.</p> <h1>Alternative 2 - Alias the methods</h1> <p>You still write utility functions as static methods hanging off util classes, but you alias them so you can access them with a shorter name, ex:</p> <pre><code>import mx.binding.utils.BindingUtils; var bind:Function = BindingUtils.bindProperty; </code></pre> <p>Now you can just call</p> <pre><code>bind(...); </code></pre> <p>rather than than the lengthy</p> <pre><code>BindingUtils.bindProperty(...); </code></pre> <p>You can do this within the class scope and the function scope, but not the package scope - because apparently you can only have one visible attribute inside a package. If you do this in the class scope, you will want to make sure it doesn't conflict with your other class attribute names.</p> <h1>Alternative 3 - use include</h1> <p>As described in <a href="http://flexonrails.net/?p=73" rel="nofollow noreferrer">this flexonrails blog post</a> you can use <em>include</em> to simulate a mixin in ActionScript. An <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=usingas_4.html#218626" rel="nofollow noreferrer">include</a> is different from an import in that all it's doing is copying the entirety of the file you are including from and paste it into the place you are including it at. So, it has completely no handling of namespace issues, you can not reference its full path name afterwards like you can with imports, if you have conflicting names, you are on your own with this. Also unlike import, it creates different copies of the same code. But what you <em>can</em> do with this is put any number of functions in a file, and include them into class or function scope in another file. Ex:</p> <pre><code>// util/time_utils.as function convertTime(..){ ... } function convertDate(..){ ... } </code></pre> <p>To include:</p> <pre><code>include 'util/time_util.as'; // this is always a relative path ... convertTime(...); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload