Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately, there is no proper way of getting all loaded classes or anything like that in the Flash API right now. So finding all sub-classes of <code>Component</code> is out, inspecting all classes for a specific meta tag is out as well.</p> <p><em>A while ago I did run into a class/function that inspected the SWF's own bytecode upon loading to retrieve all contained classes. That's the only option for this kind of thing. See <a href="http://etcs.ru/pre/getDefinitionNamesSource/" rel="nofollow">this link</a> and the bottom of my post.</em></p> <p>So, you're left with having to specify a list of component classes to pick from.</p> <p><em>One overly complicated/unfeasible option that comes to mind is creating an external tool that searches your source folders, parses AS3 code and determines all sub-classes of <code>Component</code>, finally producing a list in some XML file. But that's not a task for the faint-hearted...</em></p> <p>You can probably think of a bunch of manual solutions yourself, but one approach is to keep an accessible <code>Array</code> or <code>Vector.&lt;Class&gt;</code> somewhere, for example:</p> <pre><code>public static const COMPONENT_LIST:Vector.&lt;Class&gt; = Vector.&lt;Class&gt;( [ CollisionComponent, VisualComponent, StatsComponent, ... ... ] ); </code></pre> <p>One advantage over keeping a list of <code>String</code> names, for example, would be that the component classes are guaranteed to be compiled into your SWF.</p> <p>If the classes aren't explicitly referenced anywhere else in your code, they are not compiled. This might occur for a simple component which you only <code>update()</code> once per frame or so, and is only specified by a string in some XML file.</p> <p><strong>To clarify:</strong> You could use the code in the link above to get a list of the names of all loaded classes, then use <code>getDefinitionByName(className)</code> for each of them, followed by a call to <code>describeType(classObj)</code> to obtain an XML description of each type. Then, parsing that for the type's super-types, you could determine if it extends <code>Component</code>. <em>I personally would just hardcode a list instead; it feels too messy to me to inspect</em> all <em>loaded classes on startup, but it's up to you.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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