What's the best way to ensure that a class gets linked into the SWF?
Obviously a reference to the class from outside of the class will do it, but
is there any pattern for forcing a class to be linked in?

Troy.


On 6/6/07, Gordon Smith <[EMAIL PROTECTED]> wrote:

   The getDefinitionByName() function in the flash.utils package can
convert a String specifying a fully-qualified classname to a Class, as long
as the class is actually in the SWF or the Player. For example,

    var c:Class = Class(getDefinitionByName("mx.controls.Button"));

is the same as

    var c:Class = Button;

- Gordon

 ------------------------------
*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *phall121
*Sent:* Wednesday, June 06, 2007 9:06 AM
*To:* [email protected]
*Subject:* [flexcoders] Converting a string to a Class

 Embarrassingly basic:

How, in AS, can you convert a string ("components.Comp1") into the
actual reference to the component?

I have a function that requires a parameter of type Class.

private function fAddCustomView(compClass:Class):void

From an array I have a listing of package/components (as string):

"components.Comp1"
"components.Comp2"
"components.Comp3"

How can I convert these strings to actual references to the
components themselves...so I can send any selection into the
function as a Class?

I tried:
private function fAddComp():void
{
var clComp:Class = Class(acCompList.getItemAt(2).compname);
fAddCustomView(clComp);
}

private function fAddCustomView(compClass:Class):void

This didn't work. Error said:

"Type Coercion failed: cannot convert "components.Comp1" to Class."

Seems a basic question...How do you do it? Thanks.

Reply via email to