actionscript 3 - Flex/AS3 : Automatically instantiate package classes in an array (plugin classes) -


This is my first time here, but I have already received some good answers, so I want to thank everyone. . / P>

I am developing a small flex application and I want to extract every class from one package to the array, so I can parse it later. To clarify, I am trying to reduce a plugin management system for my application, with old canProcess / doProcess routine: My plugins are in one package, which also includes an abstract plugin class. First of all, I prepare an example of every class in this package (where I need help) and put them in an array. Then, whenever I need a plugin for any item, I parsed every plug-in class with the canProcess method (item parameter) in my beginning. If a plugin says yes, then I send the item in two process method and stop parsing the array.

I know that I can apply every class in my package by hand, but I do not want to bother doing this.

Thx

AS3 reflection does not allow you to list all classes in the package. You have to write class names in the (XML) file on the server, load it and then use those strings to get the class object and then instantiate them.

Consider the sample xml file:

  & lt; Root package = "boris.ratak" & gt; & Lt; ClassName & gt; Plugin1 & lt; / ClassName & gt; & Lt; ClassName & gt; Plugin2 & lt; / ClassName & gt; & Lt; ClassName & gt; Plugin3 & lt; / ClassName & gt; & Lt; / Root & gt;  

Parsing it by loading:

  import flash.utils.getDefinitionByName; Var pack: string = string (xml. @ Package) + "."; For each (var cl: string in xml.className) {var name: string = pack + string (cl.text ()); Var type: class = getDefinitionByName (name) in the form of class; PluginArray.push (new type ()); }  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -