From timeline?

import extremefx_comar.i18n.locales.EN_US;

trace(EN_US.test);
var n:String = "extremefx_comar.i18n.locales.EN_US";
var klass:Class = getDefinitionByName(n) as Class;
trace(klass);
var ca:Object = new klass();
trace(ca);

Output:
boo
[class EN_US]
[object EN_US]

Kenneth Kawamoto
http://www.materiaprima.co.uk/

Marcelo Volmaro wrote:
The problem is, I'm using getDefinitionByName in other places, and it works fine.

The specific class (EN_US) is included, but I can't instantiate it. Also, I was wrong on one of my statements: The trace of the static var (trace(klass.test)) worked fine.

That what makes this a mystery for me.. The class is on the flash, accessing its static member works, but instantiating it does not.

On Fri, 08 Feb 2008 13:18:27 -0300, Kenneth Kawamoto <[EMAIL PROTECTED]> wrote:

If I do this I get all the traces:

(Document class)
package {
    import flash.display.Sprite;
    import flash.utils.describeType;
    import flash.utils.getDefinitionByName;
    import extremefx_comar.i18n.locales.EN_US;
public class Test extends Sprite { public function Test():void {
            trace(EN_US.test);
            var n:String = "extremefx_comar.i18n.locales.EN_US";
            var klass:Class = getDefinitionByName(n) as Class;
            trace(klass);
            try {
                klass = Class(getDefinitionByName(n));
                trace(describeType(klass));
            } catch (e:Error){
                trace("catch error:"+e);
            }
            if (klass != null){
                trace(klass.test);
                try {
                    var ca:Object = new klass();
                    trace(describeType(ca));

                } catch (e2:Error){
                    trace("catch error2:"+e2);
                }
} }
    }
}

not sure if this helps though...

Kenneth Kawamoto
http://www.materiaprima.co.uk/

Marcelo Volmaro wrote:
Hi!,
I'm trying to do something pretty simple: dynamically instantiate a class based on it's name:
 var n:String = "extremefx_comar.i18n.locales.EN_US";
var klass:Class = null;
try {
    klass = Class(getDefinitionByName(n));
    trace(describeType(klass));
               } catch (e:Error){
    trace("catch error:"+e);
}
           if (klass != null){
    trace(klass.test);
                   try {
        var ca:Object = new klass();
        trace(describeType(ca));
                       } catch (e2:Error){
        trace("catch error:"+e2);
    }
}
The first trace works fine, no errors (so the describetype returns the correct XML for that class). Now, when I try to instantiate that class (var ca:Object = new klass()) i get the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference. Also, the klass has a public static var "test". The trace(klass.test) returns undefined.
 Ideas?
 Thanks in advance,
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to